perf: fast path string self concat#138
Conversation
Greptile SummaryThis PR implements a narrow statement fast path for repeated string self-concat (
Confidence Score: 5/5The change is safe to merge; the fast path activates only when a strict set of structural and runtime guards all pass, and the fallback to normal eval is exercised for every case that cannot be proven safe. All three gate conditions (AST shape, side-effect freedom, binding type) are checked before any mutation occurs. coerce_string_concat_rhs faithfully mirrors the (String, b) arm of the existing binary + operator, preserving TypeMode semantics exactly. The test suite covers the aliasing edge case, RHS error atomicity, all three TypeMode tiers, function call fall-through, and the chained multi-term case. No files require special attention. Important Files Changed
Reviews (2): Last reviewed commit: "fix: document string concat accumulator ..." | Re-trigger Greptile |
Summary
s = s + piece) to avoid the O(n²) clone cliff.examples/perf/string_concat_cli.tntand updates DD-061 with measured before/after results and next-step guidance.Benchmark
Local dev-release microbenchmarks against
origin/main(0491a74):s = s + "x", 100k iterations: median0.770s→0.030ss = s + "x", 200k iterations: median4.760s→0.060ss = s + piece + "y", 100k iterations: median5.370s→0.040ss = s + piece + "y", 200k iterations: median26.100s→0.070sVerification
cargo fmtcargo build --profile dev-releasecargo test string_self_concat --lib -qcargo test environment_append_to_string_binding --lib -qcargo test array_self_append --lib -qcargo test --lib -qcargo test --test language_features_tests --test type_checker_tests --test cli_tests -qcargo test./target/dev-release/ntnt docs --generate./target/dev-release/ntnt lint examples/perf/string_concat_cli.tntcargo fmt -- --checkgit diff --check