Skip to content

Remove the quadratic bookkeeping that dominated parsing large hierarc… - #648

Merged
julianspeith merged 1 commit into
masterfrom
perf/netlist-bookkeeping
Sep 10, 2026
Merged

Remove the quadratic bookkeeping that dominated parsing large hierarc…#648
julianspeith merged 1 commit into
masterfrom
perf/netlist-bookkeeping

Conversation

@julianspeith

Copy link
Copy Markdown
Contributor

…hical netlists

Two linear scans in the netlist core turned the Verilog parser quadratic on hierarchical netlists (OpenTitan Earl Grey: 25,906 modules, 1.86 million nets created and 460k merged away, 2.3 million endpoints):

  • Deleting a gate, net, or module removed it from the netlist's (and the module's) object vector with a linear std::find. The vectors now keep the position of every element in a map, and removal is a swap with the last element in constant time (utils::indexed_vector_push_back / erase).

  • Module::is_parent_module_of walked this module's whole subtree; for the top-level modules that is the entire hierarchy, once per endpoint whenever module nets are recomputed. It now walks up the parent chain of the queried module, bounded by the hierarchy depth. Module::set_parent_module detaches the module and updates its parent before the old parent re-checks its nets, which the upward walk requires.

Release parse of the 216 MB Earl Grey netlist: 709 s -> 31 s. All netlist, module, net, gate, and grouping tests pass.

…hical netlists

Two linear scans in the netlist core turned the Verilog parser quadratic on
hierarchical netlists (OpenTitan Earl Grey: 25,906 modules, 1.86 million nets
created and 460k merged away, 2.3 million endpoints):

- Deleting a gate, net, or module removed it from the netlist's (and the
  module's) object vector with a linear std::find. The vectors now keep the
  position of every element in a map, and removal is a swap with the last
  element in constant time (utils::indexed_vector_push_back / erase).

- Module::is_parent_module_of walked this module's whole subtree; for the
  top-level modules that is the entire hierarchy, once per endpoint whenever
  module nets are recomputed. It now walks up the parent chain of the queried
  module, bounded by the hierarchy depth. Module::set_parent_module detaches
  the module and updates its parent before the old parent re-checks its nets,
  which the upward walk requires.

Release parse of the 216 MB Earl Grey netlist: 709 s -> 31 s. All netlist,
module, net, gate, and grouping tests pass.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@julianspeith
julianspeith enabled auto-merge (squash) September 10, 2026 09:42
@julianspeith
julianspeith merged commit 20ffa0a into master Sep 10, 2026
4 of 6 checks passed
@julianspeith
julianspeith deleted the perf/netlist-bookkeeping branch September 10, 2026 09:42
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.

1 participant