-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
"Tearing off" a method is extremely slow #551
Comments
The first loop contains one function call per iteration. To make the loops comparable, closure1 should also return a closure: closure1 = () => () => test.tearOff(); With this change I measure 180x hit. So creating tear-offs really is terribly slow. Another interesting comparison is to make the loops comparable the other way: closure2 = test.tearOff; This creates a tear-off once and calls it many times. cc @jmesserly. |
Added this to the Later milestone. |
I'm not sure if this is still a problem. However, if it is, would it be possible to add an option to help us find performance problems related to this? |
Fixes #551 BUG= [email protected] Review URL: https://codereview.chromium.org/1998843002 .
…string_scanner, test, test_descriptor, vector_math Revisions updated by `dart tools/rev_sdk_deps.dart`. dartdoc (https://github.com/dart-lang/dartdoc/compare/06d7288..a04ac3e): a04ac3e8 2023-07-19 Sam Rawlins Format testing and fix static-type-parameter issue (#3465) a44ecebc 2023-07-19 Sam Rawlins Move validation-related tasks to package:args (#3463) 392812e4 2023-07-17 dependabot[bot] Bump analyzer from 5.13.0 to 6.0.0 (#3458) 642e8d8b 2023-07-17 Sam Rawlins Convert 'p' prefixes to 'path' in test/ (#3462) ecosystem (https://github.com/dart-lang/ecosystem/compare/2052a4c..27ff3e9): 27ff3e9 2023-07-19 Moritz Add debug message (#142) 02703ce 2023-07-18 Moritz Split commenting into new workflow (#141) a52ac63 2023-07-18 Moritz Finish renaming `coverage_web` (#140) ffa1ecb 2023-07-17 Moritz Health workflow updates (#134) leak_tracker (https://github.com/dart-lang/leak_tracker/compare/515612e..098bafc): 098bafc 2023-07-20 fzyzcjy Update pubspec.yaml (#75) 7606fd1 2023-07-19 Polina Cherkasova Improve performance. (#98) e6778b3 2023-07-18 Polina Cherkasova Explain case when static object causes leaks. (#96) cca1d77 2023-07-18 dependabot[bot] Bump actions/checkout from 3.5.2 to 3.5.3 (#86) markdown (https://github.com/dart-lang/markdown/compare/ee4e1b3..faabb1a): faabb1a 2023-07-17 Kevin Moore Bump pkg:http (dev) dependency (#551) mime (https://github.com/dart-lang/mime/compare/bdb66bd..799b398): 799b398 2023-07-18 Kevin Moore update lints, require Dart 3 (#101) d17e3ed 2023-07-18 Kevin Moore blast_repo fixes (#100) native (https://github.com/dart-lang/native/compare/7c474e1..2598ac6): 2598ac6 2023-07-20 Daco Harkes Package name spacing (#101) 3d73b4a 2023-07-19 Daco Harkes [native_assets_builder] Builder `out/` folder (#99) 6308330 2023-07-19 Daco Harkes Remove compiled files (#92) string_scanner (https://github.com/dart-lang/string_scanner/compare/35657e2..413b57a): 413b57a 2023-07-18 Kevin Moore Require Dart 3, update lints (#61) 53690da 2023-07-18 Kevin Moore blast_repo fixes (#60) test (https://github.com/dart-lang/test/compare/a92b5bb..37e54e3): 37e54e32 2023-07-19 Nate Bosch Handle initial message entirely within conditional (#2067) e76bffe8 2023-07-19 Nate Bosch Expand dom interop to cover more uses (#2066) 8bc188f7 2023-07-18 Lukas Klingsbo docs: Fix grammar and typos in Checks readme (#2058) test_descriptor (https://github.com/dart-lang/test_descriptor/compare/54a4c59..36d8617): 36d8617 2023-07-18 dependabot[bot] Bump actions/checkout from 3.5.2 to 3.5.3 (#53) vector_math (https://github.com/google/vector_math.dart/compare/c147038..048777a): 048777a 2023-07-19 moritzblume Fix rotation around Y axis (#262) 47a08ea 2023-07-17 dependabot[bot] Bump actions/checkout from 3.3.0 to 3.5.2 (#293) Change-Id: Id8010082c818c995aa7968327f98f347ff45761d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/315221 Commit-Queue: Devon Carew <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
This issue was originally filed by [email protected]
The following code times two operations:
On my machine (Mac Pro, OS X 10.5.8) the second approach is about 1700 times slower in the VM.
class Test {
Test();
void tearOff() {}
}
class Benchmark {
Test test;
Function closure1;
Function closure2;
Benchmark();
void run() {
test = new Test();
closure1 = () => test.tearOff();
closure2 = () => test.tearOff;
for (int iter = 0; iter < 10; iter++) {
bench();
}
}
void bench() {
Stopwatch w1 = new Stopwatch();
w1.start();
for (int i = 0; i < 10000; i++) {
closure1();
}
w1.stop;
double t1 = w1.elapsedInUs() / 10000;
Stopwatch w2 = new Stopwatch();
w2.start();
for (int i = 0; i < 10000; i++) {
closure2()();
}
w2.stop;
double t2 = w2.elapsedInUs() / 10000;
print("$t1$t2 $ {t2 / t1}");
}
}
void main() {
new Benchmark().run();
}
The text was updated successfully, but these errors were encountered: