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

Use Vec.apply instead of new Vec in VecInit.apply #825

Merged
merged 1 commit into from
May 24, 2018
Merged

Conversation

jackkoenig
Copy link
Contributor

The Vec constructor invokes the gen argument for each element in the
Vec. Since VecInit invokes cloneSupertype which touches every element of
the input Seq, this was an n^2 operation. Vec.apply accepts its
arguments by value so cloneSupertype is only called once. It then calls
cloneType on that once for each element in the Vec, which is constant
time reducing the overall complexity of VecInit to just n.

Type of change: other enhancement

Impact: no functional change

Development Phase: implementation

Release Notes
Speed up VecInit performance by a factor of n

The Vec constructor invokes the gen argument for each element in the
Vec. Since VecInit invokes cloneSupertype which touches every element of
the input Seq, this was an n^2 operation. Vec.apply accepts its
arguments by value so cloneSupertype is only called once. It then calls
cloneType on that once for each element in the Vec, which is constant
time reducing the overall complexity of VecInit to just n.
@jackkoenig jackkoenig requested a review from ducky64 May 24, 2018 22:02
@jackkoenig
Copy link
Contributor Author

Building on #824, this PR further reduces VecInit(Seq.fill(16384)(true.B)) runtime from ~5s to <100ms

Copy link
Contributor

@ducky64 ducky64 left a comment

Choose a reason for hiding this comment

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

lgtm

@jackkoenig jackkoenig merged commit e03e3f7 into master May 24, 2018
@ucbjrl ucbjrl added this to the 3.1.1 milestone Nov 30, 2018
@edwardcwang edwardcwang deleted the vecinit-perf branch March 15, 2019 20:02
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.

3 participants