Skip to content

Optimize routing and geometry hot paths - #1012

Draft
KRRT7 wants to merge 18 commits into
gdsfactory:mainfrom
KRRT7:shadow-main
Draft

Optimize routing and geometry hot paths#1012
KRRT7 wants to merge 18 commits into
gdsfactory:mainfrom
KRRT7:shadow-main

Conversation

@KRRT7

@KRRT7 KRRT7 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • optimize spatial overlap checks with bbox pruning and cached instance-region extraction
  • refactor BasePort away from pydantic and reduce routing placement materialization
  • vectorize NumPy-backed geometry helper paths
  • cache merge diff instance regions and reduce routing bbox region merges

Notes

  • pytest-benchmark benchmark files were moved off this branch and preserved on KRRT7/kfactory:shadow-main-pytest-benchmarks

Testing

  • not rerun after dropping benchmark-only artifacts
  • prior focused routing validation passed: uv run pytest tests/test_routing.py::test_smart_routing tests/test_routing.py::test_route_smart_waypoints_trans -q

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.63660% with 146 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.24%. Comparing base (f61117b) to head (cb9c3d6).

Files with missing lines Patch % Lines
src/kfactory/schematic.py 34.66% 40 Missing and 9 partials ⚠️
src/kfactory/routing/optical.py 81.15% 24 Missing and 12 partials ⚠️
src/kfactory/routing/generic.py 7.14% 13 Missing ⚠️
src/kfactory/kcell.py 31.25% 9 Missing and 2 partials ⚠️
src/kfactory/port.py 81.35% 9 Missing and 2 partials ⚠️
src/kfactory/routing/route_ports.py 80.35% 8 Missing and 3 partials ⚠️
src/kfactory/factories/straight.py 89.47% 2 Missing and 2 partials ⚠️
src/kfactory/enclosure.py 95.38% 1 Missing and 2 partials ⚠️
src/kfactory/checks.py 91.66% 2 Missing ⚠️
src/kfactory/layout.py 93.54% 1 Missing and 1 partial ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1012      +/-   ##
==========================================
+ Coverage   71.07%   71.24%   +0.17%     
==========================================
  Files          72       74       +2     
  Lines       14809    15269     +460     
  Branches     2882     2944      +62     
==========================================
+ Hits        10525    10879     +354     
- Misses       3386     3461      +75     
- Partials      898      929      +31     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

KRRT7 added 16 commits July 9, 2026 02:13
Add shared bbox overlap pruning and cached instance-region extraction for collision checks. Also keeps merge diagnostics named and avoids extra layout cell scans during reads.
Cache repeated router state inside the side-routing loop and keep the prior state fix in the same focused routing commit.
Replace BasePort's pydantic model with a slotted implementation, add lightweight RoutePort views for routing internals, cache DBU cross sections, and reduce straight/route placement object materialization.
Vectorize Bezier, circular, simplify, Euler, and static path extrusion point generation paths without carrying the pytest-benchmark files on this branch.
Reuse recursive per-instance regions when rendering merge differences so repeated array transforms do not rebuild the same regions.
Build the bbox obstacle region first and merge it once, avoiding repeated region merges during smart-route setup.
@sebastian-goeldi

Copy link
Copy Markdown
Collaborator

Can we split this a bit up? I am certain there are some critical paths that impact run time. But this is way too big for me to properly review

@KRRT7

KRRT7 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

@sebastian-goeldi this PR builds on top of the 3 other open PRs I have atm, if we work on them and get them merged, or closed, whichever, this PR will collapse itself to only the revelant stuff

@KRRT7

KRRT7 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

also I decided to open this large PR because it's easier to demonstrate the E2E perf wins.

@KRRT7

KRRT7 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

@sebastian-goeldi dropped the 3 currently opened PRs from this branch, so it narrows things down a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants