-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Avoid boxing FlagSets in union and allOf #3497
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
Conversation
def union(flagss: FlagSet*) = (EmptyFlags /: flagss)(_ | _) | ||
def union(flagss: FlagSet*): FlagSet = { | ||
var flag = EmptyFlags | ||
for (f <- flagss) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to go deep in micro-optimizations, you could use a while loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should avoid FlagSet*
altogether.
@@ -172,12 +172,24 @@ object Flags { | |||
} | |||
|
|||
/** The union of all flags in given flag set */ | |||
def union(flagss: FlagSet*) = (EmptyFlags /: flagss)(_ | _) | |||
def union(flagss: FlagSet*): FlagSet = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still going to box, isn't it? FlagSet*
becomes Seq[FlagSet]
, value classes in generic positions are always boxed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We avoid reboxing in the fold, half of the boxes are gone.
test performance please |
I do not believe the performance should change much |
performance test scheduled: 1 job(s) in queue, 0 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/3497/ to see the changes. Benchmarks is based on merging with master (b95e71a) |
When bootstrapping dotty, this reduces the allocated
FlagSets
from 2.7M to 400K.