mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-11 01:02:01 +03:00
Change Workspace.resolving stack from string[] to Set<string> to make cycle detection check O(1) instead of O(N). Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
653 B
653 B
2023-11-20 - O(1) Cycle Detection in Workspace resolving
Learning: When resolving deep, interdependent variables across sheets, checking a string[] stack for cycles using .includes() can degrade performance significantly (O(N) lookup repeatedly). Changing the stack representation to a Set<string> improves the check to O(1) and substantially drops resolution time from ~180ms to ~0.5ms under load.
Action: Whenever a unique set of items is tracked primarily for existence checking (like a cycle detection or "visiting" stack), prefer Set over Array if sequence order is not strictly necessary or if removal by value is possible.