intel / rohd

The Rapid Open Hardware Development (ROHD) framework is a framework for describing and verifying hardware in the Dart programming language.
https://intel.github.io/rohd-website
BSD 3-Clause "New" or "Revised" License
370 stars 65 forks source link

Performance bug: List view wrapping a Set for `Module.subModules` #489

Closed mkorbel1 closed 2 months ago

mkorbel1 commented 2 months ago

Describe the bug

In Module, the subModules API uses an UnmodifiableListView to view a collection _modules which is a Set. When subModules is iterated upon, this gets a huge performance penalty when the number of sub-modules is large. This was noticed in long run-times for generating SystemVerilog due to a for (final subModule in module.subModules) in _SynthModuleDefinition in "systemverilog.dart".

To Reproduce

Create a large (~50k originally found this) number of sub-modules within a module and generate the SystemVerilog.

Expected behavior

Fast

Actual behavior

Slow

Additional: Dart SDK info

No response

Additional: pubspec.yaml

No response

Additional: Context

We should create a benchmark that reproduces and protects against this issue.

We should do a review for any other similar issues.