perf(layout,parser-sql): Reduce hot-path allocations in edge routing and object name parsing#85
Merged
Merged
Conversation
Previously the routing loop allocated a new Vec<Rect> on each edge, copying every node's rectangle minus the two endpoints. For 200 nodes and 400 edges this performed 400 allocations and ~80,000 Rect copies. Precompute the (id, Rect) list once outside the loop and reuse a single Vec<Rect> buffer per iteration, populating it with a filter that excludes the source/target nodes.
split_object_name only needs the last one or two parts of an ObjectName, but the previous implementation collected every part into a Vec<String> just to pattern-match the slice. Index the last two parts directly so single- and two-part names allocate one or two Strings instead of N + 1. Also short-circuit warn_truncated_object_name on the cheap name.0.len() check before allocating the parts vector, since the warning path only fires on > max_parts qualified names.
Code Metrics Report
Details | | main (c3c66ec) | #85 (f7821d9) | +/- |
|---------------------|----------------|---------------|-------|
+ | Coverage | 94.6% | 94.6% | +0.0% |
| Files | 77 | 77 | 0 |
| Lines | 33826 | 33842 | +16 |
+ | Covered | 32012 | 32028 | +16 |
| Test Execution Time | 1m27s | 1m27s | 0s |Code coverage of files in pull request scope (94.8% → 94.8%)
Reported by octocov |
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
Vec<Rect>allocation in the layout routing loop by precomputing theobstacle list once and reusing a single buffer across iterations
Vec<String>collection fromsplit_object_nameand from theearly-return path of
warn_truncated_object_nameso single- and two-partObjectNamelookupsno longer allocate N + 1 strings per call
Changes
(id, Rect)list of all positioned nodes out ofroute_edges_with_diagnosticsinto a one-shot
collect_node_obstacleshelper so it is built once per layout pass instead ofonce per edge
Vec<Rect>viaclear()+extend()and inline the source/targetexclusion as a filter, taking a 200-node × 400-edge graph from 400 allocations + ~80,000
Rectcopies to 1 allocation
ObjectNameparts directly instead of collecting every partinto a
Vec<String>and pattern-matching the slice, so the common single- and two-part casesallocate only the strings that are actually returned
warn_truncated_object_nameonname.0.len()first so the parts vector isonly materialized when a truncation warning actually fires