Skip to content

perf: Stream large JSONL and config files during reads to limit memory footprint - #717

Open
tteon wants to merge 2 commits into
mainfrom
perf/jsonl-streaming-2353351736081756658
Open

tteon wants to merge 2 commits into
mainfrom
perf/jsonl-streaming-2353351736081756658

Conversation

@tteon

@tteon tteon commented Oct 5, 2026

Copy link
Copy Markdown
Owner

This is a draft PR implementing a focused performance improvement regarding file I/O operations.

What

Converted multiple occurrences of the path.read_text().splitlines() anti-pattern into lazy stream iterations using the with path.open(...) as f: context manager across various scripts and tests.

Modified files:

  • scripts/agentos/e2e_axiom_ab.py
  • scripts/agentos/e2e_cold_start_ab.py
  • scripts/agentos/e2e_cross_model_intern.py
  • scripts/agentos/e2e_ontology_source_ab.py
  • scripts/benchmarks/inference_workbench.py
  • scripts/cache_sim/h0_gate.py
  • scripts/finbench/results_log.py
  • scripts/serve_track/smoke_plugin.py
  • tests/seocho/test_env_contract.py
  • tests/seocho/test_serving_image_hardening.py
  • .jules/bolt.md

Why

When dealing with large output logs, trace files, or JSONL outputs, calling .read_text() loads the entire file into a single massive string in memory, and .splitlines() then creates a massive list containing every single line. This results in heavy I/O overhead and unneeded memory pressure. Lazy iteration circumvents this by handling one line at a time.

Expected Impact

Qualitative impact only: memory usage overhead when parsing result logs and environment files will significantly decrease. It will avoid out-of-memory errors on machines processing gigabytes of trace data or JSONL lines while maintaining identical processing logic and throughput.

Validation

I ran bash scripts/ci/run_basic_ci.sh to ensure all existing test suites still pass. I verified that string matching correctly accounted for newline terminations when transitioning from splitlines() (which drops newlines) to iteration (which keeps them) by ensuring trailing newlines are properly stripped or handled.

Risks

The main risk involves subtle newline discrepancies, as read_text().splitlines() eliminates trailing \n while iterating over f retains them. To mitigate this risk, json.loads() inherently handles trailing whitespace appropriately, and for manual string matching operations, rstrip('\n') or strip() methods were used where applicable. There are no exposed architectural risks or semantic behavior changes.


PR created automatically by Jules for task 2353351736081756658 started by @tteon

Replaces the `path.read_text().splitlines()` anti-pattern with memory-efficient stream processing using context managers (`with path.open(...) as f: for line in f:`).

This prevents loading massive JSONL traces and entire file contents into a single string in memory before splitting into a list of strings, effectively capping memory footprint during file I/O operations and avoiding potential OOM crashes when analyzing large files.

Co-authored-by: tteon <52625664+tteon@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@github-actions github-actions Bot added kind-perf Performance, memory, throughput, or latency work. kind-test Test coverage, fixtures, or validation-only changes. status-needs-triage Needs maintainer triage before work starts or merges. labels Oct 5, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d020df7cf7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .jules/bolt.md
@@ -0,0 +1 @@
Learned that parsing files with json.loads(path.read_text().splitlines()) is a performance bottleneck since it loads everything into memory at once. Converting to use stream context managers like with path.open('r', encoding='utf-8') as f: provides memory efficiency and iteration.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove the tracked Jules state file

This adds a file under .jules/, which is reserved for local agent state and must remain untracked; it also makes scripts/ci/check-root-hierarchy-contract.sh fail with Forbidden tracked root hierarchy path: .jules. Remove this file from the commit rather than publishing the task note.

AGENTS.md reference: AGENTS.md:L53-L54

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-05T23:35:56.199313Z d020df7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Replaces the `path.read_text().splitlines()` anti-pattern with memory-efficient stream processing using context managers (`with path.open(...) as f: for line in f:`).

This prevents loading massive JSONL traces and entire file contents into a single string in memory before splitting into a list of strings, effectively capping memory footprint during file I/O operations and avoiding potential OOM crashes when analyzing large files.

Co-authored-by: tteon <52625664+tteon@users.noreply.github.com>
@github-actions github-actions Bot added area-ci GitHub Actions, CI scripts, release automation, or repo ops. kind-ci CI, repository automation, release automation, or labels. labels Oct 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-ci GitHub Actions, CI scripts, release automation, or repo ops. kind-ci CI, repository automation, release automation, or labels. kind-perf Performance, memory, throughput, or latency work. kind-test Test coverage, fixtures, or validation-only changes. status-needs-triage Needs maintainer triage before work starts or merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant