Skip to content
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

Fix bundle elements performance regression #2396

Merged
merged 2 commits into from
Feb 4, 2022

Conversation

jackkoenig
Copy link
Contributor

@jackkoenig jackkoenig commented Feb 3, 2022

I previously measured that #2306 improved the performance of Chisel3 on a typical large SiFive design by 16%, more careful measurements show that number to actually be 30%.

However, this benefit only comes if the user uses the scalacOption -P:chiselplugin:genBundleElements which tells the Chisel compiler plugin to generate Bundle.elements. I then tried this typical large SiFive design without that scalacOption and I found Chisel to run 21% slower. Considering most users will bump to 3.5.1 and won't apply that new scalacOption immediately (if they ever do), this slowdown is unacceptable.

This PR changes 2 small things:

  1. Only call _elementsImpl once in Bundle.elements -- this mitigates most of the slowdown but not all of it. It also speed up the case when folks are using -P:chiselplugin:genBundleElements (although probably a very small amount).
  2. Make the reflective _elementsImpl use the exact old implementation of Bundle.elements, Bundle.elements then matches on the output of _elementsImpl and just returns immediately when its the reflective implementation.

This appears to fully mitigate the slowdown.

I tested this on SiFive designs as well as by disabling Bundle.elements generation in the chisel3 tests and running sbt test.

Contributor Checklist

  • Did you add Scaladoc to every public function/method?
  • Did you add at least one test demonstrating the PR?
  • Did you delete any extraneous printlns/debugging code?
  • Did you specify the type of improvement?
  • Did you add appropriate documentation in docs/src?
  • Did you state the API impact?
  • Did you specify the code generation impact?
  • Did you request a desired merge strategy?
  • Did you add text to be included in the Release Notes for this change?

No release notes necessary because this feature is not yet released.

Type of Improvement

  • bug fix
  • performance improvement

API Impact

No impact

Backend Code Generation Impact

No impact

Desired Merge Strategy

  • Squash

Release Notes

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels?
  • Did you mark the proper milestone (Bug fix: 3.4.x, [small] API extension: 3.5.x, API modification or big change: 3.6.0)?
  • Did you review?
  • Did you check whether all relevant Contributor checkboxes have been checked?
  • Did you mark as Please Merge?

@jackkoenig jackkoenig added this to the 3.5.x milestone Feb 3, 2022
@jackkoenig jackkoenig force-pushed the fix-bundle-elements-perf-regression branch 3 times, most recently from 878a9ca to b642a2f Compare February 4, 2022 00:23
@jackkoenig jackkoenig requested a review from chick February 4, 2022 00:23
Bundle.elements now will only do post-processing if the user is using
plugin-generated _elementsImpl. This improves performance for the case
where the user does not opt-in to using the plugin to generate
_elementsImpl.
@jackkoenig jackkoenig force-pushed the fix-bundle-elements-perf-regression branch from b642a2f to f8e1454 Compare February 4, 2022 00:33
Copy link
Contributor

@chick chick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the solution

@jackkoenig jackkoenig merged commit 5fead89 into master Feb 4, 2022
@jackkoenig jackkoenig deleted the fix-bundle-elements-perf-regression branch February 4, 2022 01:43
mergify bot pushed a commit that referenced this pull request Feb 4, 2022
* Only call _elementsImpl once in Bundle.elements

* Distinguish compiler plugin and reflective _elementsImpl

Bundle.elements now will only do post-processing if the user is using
plugin-generated _elementsImpl. This improves performance for the case
where the user does not opt-in to using the plugin to generate
_elementsImpl.

(cherry picked from commit 5fead89)
@mergify mergify bot added the Backported This PR has been backported label Feb 4, 2022
mergify bot added a commit that referenced this pull request Feb 4, 2022
* Only call _elementsImpl once in Bundle.elements

* Distinguish compiler plugin and reflective _elementsImpl

Bundle.elements now will only do post-processing if the user is using
plugin-generated _elementsImpl. This improves performance for the case
where the user does not opt-in to using the plugin to generate
_elementsImpl.

(cherry picked from commit 5fead89)

Co-authored-by: Jack Koenig <koenig@sifive.com>
jackkoenig pushed a commit that referenced this pull request Feb 28, 2023
* Add option to disable random mem/reg init

Co-authored-by: Jiuyang Liu <liu@jiuyang.me>

* fix for code review.

Co-authored-by: SharzyL <me@sharzy.in>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported This PR has been backported release issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants