perf(diff): view-based LineCache::processed, no per-line copies - #220
Merged
Conversation
Data::Process copied every line into LineCache::processed even when no transformation applied, and copied pure-substring results (trailing space trim, comment truncation) that could alias the input. LineCache::processed is now a std::string_view backed by (a) the raw line on the default path, (b) a sub-range of it for suffix trims and comment truncation, or (c) a Data-owned std::deque<std::string> arena for rebuilding transformations (all/consecutive space, parsed comments, regex replace - the latter now only materializes when a replacement actually occurred). The deque never moves elements, so views stay valid; the vector of LineCache elements no longer self-references (also fixed the off-by-one reserve that forced a reallocation). Tokenize-heavy benchmark medians (same-session A/B): default 8.77->7.02ms (-20%), trailing-space 10.3->6.91ms (-33%, allocation free), all-space 22.5->18.2ms (-19%), ignore-case 11.1->9.52ms (-14%).
helly25
enabled auto-merge (squash)
July 4, 2026 13:04
Fab-Cat
approved these changes
Jul 4, 2026
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
Second half of the preprocessing perf work (follow-up to #218, closes the layer identified there):
Data::Processcopied every line of every file intoLineCache::processed— even when no transformation applied — and copied pure-substring results that could alias the input.LineCache::processedis now astd::string_viewbacked by:ignore_trailing_spacesuffix trim;strip_commentstruncation),Data-ownedstd::deque<std::string>arena for rebuilding transformations (ignore_all_space,ignore_consecutive_space, parsed comment stripping,regex_replace_*— the latter now only materializes when a replacement actually occurred).The deque never moves its elements, so views stay valid, and
LineCacheelements no longer self-reference — which also let me fix the off-by-onereserve()(N newlines → N+1 lines) that previously forced a mid-build reallocation.Benchmark (tokenize-heavy cases from #218, 7-rep medians, same-session A/B):
Semantics unchanged; consumers (
CompareEq, the Myers tokenizer) already operate onstring_view-compatible types.Test plan
bazel test //mbo/diff/...— 40/40 pass (feature matrix, ignore-option corner cases, Myers round-trip corpus, all goldens).bazel run -c opt //mbo/diff:diff_benchmark -- --benchmark_filter=tokenizefor the numbers above.