Render each context once per cycle instead of re-reading per visited file#21
Draft
krlittle wants to merge 1 commit into
Draft
Render each context once per cycle instead of re-reading per visited file#21krlittle wants to merge 1 commit into
krlittle wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A more targeted alternative to the combination of Stream CsvDataTableStore.getRows from disk lazily instead of buffering the whole table rewrite#7858 + Stream data table rows into context files and render each context once #20, with a much smaller blast radius. It fixes the same redundant-work problem in
ExportContext, but as a single-file change in this repo — no change to the sharedrewrite-coreCsvDataTableStore, and no two-repo release coordination.ExportContextrenders each context once per cycle and caches the rendered output on its accumulator, sogenerate()andgetVisitor()reuse it instead of re-aggregating the same data tables for every visited context file and again in the forced second export cycle. Reads per table drop from2 × (F + 2)to2(forFcontext CSVs).It does not change how rows are read — each render still materializes the table once via the existing
aggregateMatchingTables/exportToCsvpath.Output is byte-identical.
Problem
ExportContextreads its referenced data tables back to write.moderne/context/*.csv, re-reading and re-rendering each table once ingenerate(), once for every context CSV visited ingetVisitor(), and again in the forced second cycle — roughly2 × (F + 2)full reads per table (~42× for a repo emitting 19 context CSVs). For large repositories (one row per method/class) that is a lot of redundant decompress/parse/render work per repo.Why an alternative — and the tradeoff
CsvDataTableStore.getRows) plus Stream data table rows into context files and render each context once #20 (stream rows inExportContext) together remove the redundant re-reads and the per-render buffering, so a table is never held in memory at any layer. But that combination spans two repos — including a change to the sharedrewrite-corestore used by every recipe and tool — and the rewrite-core change has to ship before prethink sees the full benefit.This PR removes only the redundant re-reads (the dominant cost) and stays entirely within
rewrite-prethink:|---|---|---|
| Redundant re-reads removed | ✅ ~21× fewer | ✅ ~21× fewer |
| Per-render table buffering removed | ❌ still buffers once | ✅ streamed; never buffered |
| Files / repos touched | 1 file, this repo | 2 repos incl. shared
rewrite-core|| Release coordination | none | rewrite-core must ship first |
| Blast radius | this recipe only | every
CsvDataTableStoreconsumer |Opening as a draft to surface the tradeoff for technical review: is avoiding the in-memory buffering worth the two-repo / shared-core change, or is this contained cache-only step the better tradeoff? We'd land one path, not both.
Test plan
ExportContextTestpasses unchanged, including the exact CSV-row + markdown content assertions inaggregatesRowsFromMultipleInstancesOfSameDataTable— confirming byte-identical outputaggregatesEachReferencedTableExactlyOncePerRun, which installs a countingDataTableStoreand asserts each referenced table is read once per export cycle (2 total), not once per visited context file