-
Notifications
You must be signed in to change notification settings - Fork 95
Implement Robust Panel Identical-Board Detection and PropKey-Based CircuitJson Caching #1726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| getBoardPropKey, | ||
| extractBoardCircuitJson, | ||
| applyCircuitJsonToBoards, | ||
| } from "../../utils/panels/identical-board-caching" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not lib/components/normal-components/Panel/..., utils directories are generally an anti-pattern whenever they are specific (keep similar things together)
| * 1. Props (excluding position and children) | ||
| * 2. Instance children (component names and their props) | ||
| */ | ||
| export function boardsAreIdentical(a: Board, b: Board): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multiple exports again, idk why people keep breaking this rule
one export = one file
| for (const group of identicalBoardGroups) { | ||
| const [firstBoard] = group | ||
| const propKey = getBoardPropKey(firstBoard) | ||
| const cached = this._cachedBoardCircuitJsonByPropKey.get(propKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call it boardCacheKey
seveibar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think you're actually caching the boards- i.e. each board is rendered then you just replace the circuit json later. There will still be a massive performance penalty. You might need to create a RootCircuit to independently render a board
Put an event listener on the circuit to ensure that e.g. the autorouter isn't being called multiple times
|
it's something like circuit.on("autorouting:start", () => { autorouterCallsCount++ }) |
Panel Board Routing Caching
This PR adds structural board matching to panels so identical boards can reuse routing.
Only the first board in each identical group performs autorouting; the rest skip routing and copy its circuitJson output.
A routing lifecycle was added to ensure duplicates wait until the template routing finishes before applying results.
How the Duplicate Routing System Works
The system is implemented across both the Panel and Board classes and executes in several phases.
Phase 1: Detect Identical Boards
Method:
Panel.doInitialReactSubtreesRender<board>children.findIdenticalBoardGroups()to group boards based on:propKeyused for comparison and cachingmarkAsDuplicate(templateBoard)_isDuplicateBoard = true_templateBoard = templateBoardPhase 2: Skip Autorouting
Method:
Board.doInitialPcbTraceRenderWhen the PcbTraceRender phase runs:
isDuplicate()This prevents duplicate boards from starting unnecessary autorouting tasks.
Phase 3: Wait for Template Board
Method:
Board.updatePcbTraceRenderDuplicates enter a wait loop:
_asyncAutoroutingResult_applyTemplateCircuitJson()This ensures duplicates only apply routing once the template is fully done.
Phase 4: Copy Template Routing
Method:
Board._applyTemplateCircuitJsonWhen applying routing:
extractBoardCircuitJson()applyBoardCircuitJson()This makes multiple identical boards render extremely fast without recomputing traces.
Data Flow Diagram
Panel.doInitialReactSubtreesRender
→ findIdenticalBoardGroups
→ mark duplicates
→ template board runs autorouting
→ duplicates skip routing
→ duplicates wait for template to finish
→ duplicates copy template circuitJson
Key Internal Properties
_duplicateBoardToTemplate_isDuplicateBoard_templateBoard_asyncAutoroutingResultResult
Panels with repeated boards now route dramatically faster.
Three identical boards route the cost of one; ten identical boards route the cost of one, etc.
Snapshot tests confirm consistent circuitJson output and stable caching behavior.