Skip to content

perf(layout,parser-sql): Reduce hot-path allocations in edge routing and object name parsing#85

Merged
mhiro2 merged 2 commits into
mainfrom
perf/layout-routing-allocations
Apr 25, 2026
Merged

perf(layout,parser-sql): Reduce hot-path allocations in edge routing and object name parsing#85
mhiro2 merged 2 commits into
mainfrom
perf/layout-routing-allocations

Conversation

@mhiro2

@mhiro2 mhiro2 commented Apr 25, 2026

Copy link
Copy Markdown
Owner

Summary

  • Eliminate per-edge Vec<Rect> allocation in the layout routing loop by precomputing the
    obstacle list once and reusing a single buffer across iterations
  • Drop the unconditional Vec<String> collection from split_object_name and from the
    early-return path of warn_truncated_object_name so single- and two-part ObjectName lookups
    no longer allocate N + 1 strings per call

Changes

  • d929df0 : perf(layout): reuse obstacle buffer across edge routing iterations
    • Hoist the (id, Rect) list of all positioned nodes out of route_edges_with_diagnostics
      into a one-shot collect_node_obstacles helper so it is built once per layout pass instead of
      once per edge
    • Reuse a single Vec<Rect> via clear() + extend() and inline the source/target
      exclusion as a filter, taking a 200-node × 400-edge graph from 400 allocations + ~80,000 Rect
      copies to 1 allocation
  • a94b30e : perf(parser-sql): avoid Vec allocation in split_object_name
    • Index the trailing one or two ObjectName parts directly instead of collecting every part
      into a Vec<String> and pattern-matching the slice, so the common single- and two-part cases
      allocate only the strings that are actually returned
    • Short-circuit warn_truncated_object_name on name.0.len() first so the parts vector is
      only materialized when a truncation warning actually fires

mhiro2 added 2 commits April 25, 2026 23:21
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.
@mhiro2 mhiro2 self-assigned this Apr 25, 2026
@mhiro2 mhiro2 added the enhancement New feature or request label Apr 25, 2026
@github-actions

Copy link
Copy Markdown

Code Metrics Report

main (c3c66ec) #85 (f7821d9) +/-
Coverage 94.6% 94.6% +0.0%
Test Execution Time 1m27s 1m27s 0s
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%)

Files Coverage +/- Status
crates/relune-layout/src/layout.rs 95.7% +0.0% modified
crates/relune-parser-sql/src/lib.rs 93.2% 0.0% modified

Reported by octocov

@mhiro2
mhiro2 merged commit a1a3390 into main Apr 25, 2026
4 checks passed
@mhiro2
mhiro2 deleted the perf/layout-routing-allocations branch April 25, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant