perf: resolve source spans through a line index - #332
Merged
Merged
Conversation
Program::validate resolved every recorded span by scanning the retained source text from the beginning to convert each line/column position into a byte offset. The identifier and nested-value spans added in #326 roughly tripled the number of checked spans, so this repeated full-text scan dominated large real-project workloads: on the 448 KB bastion.ow fixture, Program::validate took ~8.9s in release and ~146s in debug builds. SourceDocument now records each line's byte offset once, and position resolution scans only the addressed line. Span semantics are unchanged: a differential test checks the indexed resolution against the original full-scan algorithm, and a scan-bound test fails if full-document rescans return. The bastion.ow stage benchmark is kept as an ignored performance measurement (release: validate ~10.3ms, element_count ~15.5ms; debug: validate ~119ms). Fixes #331
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
Program::validateresolved every recorded span by scanning the retained source text from the beginning for each line/column → byte-offset conversion (SourceDocument::byte_range→byte_offset). The identifier and nested-value spans added in #326 roughly tripled the number of checked spans, so this repeated full-text scan dominated large real-project workloads.SourceDocumentnow records each line's start offset once; position resolution scans only the addressed line.Measurements (
bastion.ow, 447 709 bytes; 22 139 values / 3 051 actions / 303 rules)program.validate(release)program.validate(debug)element_count(release)element_count(debug)parse/emitThe per-node public span-path traversal that the issue hypothesized (
condition_value_span/action_argument_value_spanroot-to-node lookups, 22 139 nodes) measures ~1.2 ms total in release — it was not the regression, and no parallel cache/index was added for it. The 1.0.0 baseline was already affected by the same scan; #326 amplified it into the minutes-scale dogfood regression.Falsification / regression protection
byte_offsets_match_full_document_scan: indexed resolution vs. the pre-index full-scan algorithm over a CRLF/Unicode document including boundary and overshot positions.byte_offsets_scan_only_the_addressed_line: bounds the bytes examined per resolution to one line — fails deterministically (no wall-clock threshold) if full-document rescans return.tests/perf_large_project.rs: ignored stage-level benchmark on the realbastion.owinput (same convention asaudit_benchmarks), runnable viacargo test -p workshop-rs --release --lib perf_large_project -- --ignored --nocapture.Verification
cargo fmt --all --check✅cargo clippy --workspace --all-targets -- -D warnings✅cargo test --workspace --all-targets✅ (lib 241, integration 107, cli 15+15, catalog-gen 9; 4 ignored benchmarks)cargo run -p workshop-rs --bin workshop-catalog-gen -- check✅git diff --check✅source_map,program_model,source_preservation,parser::spans_are_preserved).Known remaining similar pattern (out of scope)
settings/schema.rs::source_value_rangehas the same per-call scan but serves singleSettingSource::source_editcalls on a cold&str; it is not on the validate hot path and would need a different API to share an index.Fixes #331
Generated with Devin