-
Notifications
You must be signed in to change notification settings - Fork 29.7k
switched to a double variant of clamp to avoid boxing #103559
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
|
I wonder - is this a rare case where having an extension on |
It definitely would have made my life easier but it's my understanding it's against the style guide. |
5ed7d8b to
e2a32c9
Compare
jonahwilliams
left a comment
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.
It would be nice to have a test that ensures anyone that commits new code uses clampDouble instead of num.clamp.
See https://github.com/flutter/flutter/blob/master/dev/bots/analyze.dart for some examples of flagging code or comment patterns to fail analysis
packages/flutter/lib/src/rendering/sliver_persistent_header.dart
Outdated
Show resolved
Hide resolved
Yea, I thought the same thing. I read through that script and the only step that is actually parsing any code is |
|
@jonahwilliams does that analyze bot get run anywhere? It fails for me locally: |
|
It runs on every CI. Try |
|
It would be nice to have a lint for this somehow. I don't think we can properly lint this without having an analyzer check for it. |
|
It would also be nice if somehow the compiler can just fix this for us via TFA. @alexmarkov @a-siva |
dnfield
left a comment
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.
Please add a microbenchmark for this.
Microbenchmark added, in microbenchmarks it's actually 80x faster. (I was guessing 4x based off of what I was seeing in profiling). |
Co-authored-by: Dan Field <[email protected]>
|
(rebasing to hopefully flush out outstanding ci issues) |
|
I'm landing this despite google testing showing up yellow. The google test was run successfully in the above CL, the rerun that just happened finished but didn't update its status yet. There is one failure there out of 2190 runs. There is one failure that isn't related to this one, but has to do with apple signing certificates. |
|
I guess every single one of you has thought about this possibility, but since no one said anything, isn't it possible to fix Dart? Or at least do something there like clamp2/dangerousClamp/fastClamp, who knows? lol This is super useful. If it is too big, maybe schedule for Dart 3? I would love to see this on Dart side too. |
I'm going to file a bug with them but if you look at the the reason that this is faster, not all of them could be brought into Dart. For example we ignore nan for the limits. We can do that because we know we don't care about it. Dart can't do that. That said, my understanding is that the large part of this optimization comes from avoiding |
|
FYI @mraleph |
|
@bernaferrari we are going to fix Dart (see dart-lang/sdk#40852 and dart-lang/sdk#46879), it's not going to become as fast as custom Note that while improvement looks great/important in isolation, it hardly matters unless all you do is clamping. |
|
This PR resulted in a 4.2% increase in performance for |
This clamp performs roughly
4x12x faster than dart's. I implemented it to speed up layout_bench.dart with respect toBoxConstraints. Ultimately that change was small 1%-2% but it showed that certain usages of clamp could greatly be sped up for other hypothetical use cases.It's faster because:
numtypecompareTo0.0and-0.0intPre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.