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
374 stars 67 forks source link

Optimize `guard` subscription performance in `Combinational` #346

Closed mkorbel1 closed 1 year ago

mkorbel1 commented 1 year ago

Description & Motivation

344 introduced a performance issue with SynchronousEmitter (used in signal glitch propagation) when SynchronousSubscriptions are cancelled. Removal from a List of subscriptions was expensive and in the critical path for simulation performance when there are many Combinationals arranged in a particular way.

This PR replaces that List with a custom collection called IterableRemovableQueue which is optimized specifically for the needs of the SynchronousEmitter. It also includes a benchmark that reproduces the performance issue and tests for the new collection type.

There is still some overhead in having guard there at all, but without disabling the check there's not that much I see we can do to improve it. Moving towards recommending reduced usage of Combinational may be a good solution, since it has a number of weird characteristics (representing procedural code as hardware).

This PR also has some other refactoring of minor collection usage for efficiency based on discoveries during profiling.

Related Issue(s)

N/A

Testing

Existing tests pass, plus new ones for the benchmark and collection.

Backwards-compatibility

Is this a breaking change that will not be backwards-compatible? If yes, how so?

No

Documentation

Does the change require any updates to documentation? If so, where? Are they included?

No