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
Bitwise operations slow in VM #13869
Comments
Set owner to @iposva-google. |
The operations in the loop ... for (int i = 0; i < s.length; i++) { ... do keep overflowing the Smi range when executed on 32-bit architectures causing significant allocation of Mint objects. This can be verified by running the same program on a 64-bit build and observing a 8.5x speed improvement on the same hardware. For example: _mask31 should be 0x3fffffff to stay in signed 31-bit range. We'll keep this open to investigate why we are allocating so many Mint objects during the loop. Set owner to @sgmitrovic. |
This comment was originally written by lry@google.com Thank you for taking a look and sorry for the confusion. |
This comment was originally written by lry@google.com a version that doesn't overflow runs in 50ms, as noted by ivan: const int _mask29 = 0x1fffffff; int substringHash29(String s) { |
FYI the DOM libraries use a version of the code in #4 under the name JenkinsSmiHash. |
I am not exactly sure what different JavaScript implementations have to do with a reported performance bug in the VM, but this issue was resolved as a misunderstanding of Smi values and an overly aggressive boxing/unboxing of Mint values. |
cc @mraleph. |
Unmerging. Building on top of my latest fix that enables range inference across non-smi phis, I added logic to infer ranges for xor operation plus logic to unbox int32 phis that appear after we narrow mint operations - this brings us down to 45ms on my machine for original bitBench.dart removing all boxing in the loop. I am underging from the 13875 because there are no true Mint phis in the code - there are only int32 ones which we support. The code looks almost ok, but still has some redundancies that can be cleared away. cc @fsc8000. |
This issue was originally filed by lry@google.com
Bitwise operations run slow, discovered with an implementation of the Jenkins hash function (http://en.wikipedia.org/wiki/Jenkins_hash_function).
To avoid big numbers we applied bit masks, for example
const int _mask31 = 0x7fffffff;
hash = (hash + ((hash & 0x1fffff) << 10)) & _mask31;
Attached a dart version, which takes 300 ms for hashing a string of length 8'000'000. The JVM version (scala file attached) runs in 23ms.
Attachments:
bench.scala (864 Bytes)
bitBench.dart (862 Bytes)
The text was updated successfully, but these errors were encountered: