-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Optimization suggestion 2 #17434
Comments
cc @herhut-ggl. |
I suspect that the type of 'arg' is unknown. There will always be cases where the compiler can't quite figure out what the programmer knows is true. The programmer can help the compiler generate better code by manually doing common subexpression elimination. For example, instead of Write It is also worth while making 'storage' private. That way some other library that also has a storage field will not confuse the type analysis from inferring 'get$storage returns Float32List' to inferring 'get$storage returns union(Float32List, SomeOtherClass)' or worse. |
This comment was originally written by @Fox32 Thanks for your tips! I took your suggestions and put them into vector_math: google/vector_math.dart#63 (comment)
All these changes reduced the type and size checks of the storage a lot. At many places I could reach the code I would write myself. Any other suggestions I can take into account? Maybe a guide or howto for dartlang.com would be nice, so others could benefit from this tips, too. |
It might be worth backing out the "3. Added type checks to operators". Essentially, don't forget to profile the results too. |
This comment was originally written by @Fox32 You are right the type checks in the operators where not necessary anymore. Thanks! |
I had another idea that reduces garbage. We already renamed the 'storage', and used temps to reduce the number of accesses: class Vector2 implements Vector { ... /// Set the values by copying them from [other]. The problem with this code is that 'setFrom' is not always inlined. Vector2 setFrom(Vector2 other) { static void _setFrom(Float32List first, Float32List second) { Now if only setFrom is inlined, it might be that the compiler can see where This is more important methods that stand no chance of being inlined, like normalize (the two return statements make it harder to inline). double get length { Vector2 normalize() { --> double get length { static double _length(/Float32List/ storage) { Vector2 normalize() { static _normalize(/Float32List/ storage) { I think getting pull requests accepted will be easier if each request does something that is clearly independent and easy to review, e.g. (a) rename Vector2.storage to Vector2._storage2 and nothing else (b) stratify Vector2 like I just described. |
This comment was originally written by @Fox32 Interesting suggestions, maybe I have to look into it again... |
[user feedback]
Dart2js: arg.storage is a final field with a Float32Array. Why is it accessed multiple times? Should it be sufficient to call arg.get$storage() once?
t1 = new Float32Array(9);
t2 = this.storage;
t3 = t2[0];
t4 = arg.get$storage();
if (0 >= t4.length)
return H.ioore(t4, 0);
t4 = t4[0];
t5 = t2[3];
t6 = arg.get$storage();
if (1 >= t6.length)
return H.ioore(t6, 1);
t6 = t6[1];
t7 = t2[6];
t8 = arg.get$storage();
.......
////////////////////////////////////////////////////////////////////////////////////
Editor: 1.3.0.dev_03_02 (2014-03-10)
OS: Windows 8 - amd64 (6.2)
JVM: 1.7.0_45
projects: 2
open dart files: 0
auto-run pub: true
localhost resolves to: 127.0.0.1
mem max/total/free: 1778 / 853 / 528 MB
thread count: 29
index: 778380 relationships in 128899 keys in 1268 sources
SDK installed: true
Dartium installed: true
The text was updated successfully, but these errors were encountered: