Skip to content
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

time dilation effects in indexOf benchmark. #17437

Closed
DartBot opened this issue Mar 12, 2014 · 5 comments
Closed

time dilation effects in indexOf benchmark. #17437

DartBot opened this issue Mar 12, 2014 · 5 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends.

Comments

@DartBot
Copy link

DartBot commented Mar 12, 2014

This issue was originally filed by @tatumizer


Please run the following program (I tested on Windows, not sure if Linux has the same effect).

import 'dart:typed_data';
int iterations=10000000;
testIndexOf8() {
  var list=new Uint8List(8);
  int x=0;
  for (int i=0; i<iterations; i++) {
      x|=list.indexOf(1);
  }
  return x;
  
}
testIndexOf16() {
  var list=new Uint16List(8);
  int x=0;
  for (int i=0; i<iterations; i++) {
      x|=list.indexOf(1);
  }
  return x;
}

main() {
  var w;
  testIndexOf8(); // warmup
  testIndexOf16(); // warmup
  w = new Stopwatch()..start();
  print("result=${testIndexOf8()}, time=${w.elapsedMilliseconds}");
  
  w.reset();
  print("result=${testIndexOf16()}, time=${w.elapsedMilliseconds}");
}

printout:
result=-1, time=850
result=-1, time=884

NOTE: I print "result" just to eliminate very unlikely case where compiler can optimize stuff away.

Now let's conduct a number of experiments

  1. comment out both warmup calls:
      result=-1, time=251 -- YES! It can run by 4 times faster!
      result=-1, time=935
  2. with warmup calls both commented out, go to testIndexOf16 and replace Uint16List with Uint8List constructor:
      result=-1, time=290
      result=-1, time=240
      
    And so on. I managed to get all possible combinations of ~200, ~900 milliseconds by randomly commenting/uncommenting stuff.
      
    How one method affects the other is a mystery. One gets deoptimized because the other one gets optimized? Or one gets optimized because the other one gets de-optimized? But sometimes they are both optimized, and at other times both de-optimized? I admit I wasn't able to discover a pattern.
@fsc8000
Copy link
Contributor

fsc8000 commented Mar 12, 2014

Added Area-VM, Triaged labels.

@ghost
Copy link

ghost commented Mar 19, 2014

List.indexOf is faster when running with a monomorphic state (Uint8List) then in polymorphic (Uint8List, Uint16List) Once more than one receiver type is used for calling List.indexOf, more checks is needed. This will be solved once specialization is implemented.


Set owner to @sgmitrovic.
Added Accepted label.

@DartBot
Copy link
Author

DartBot commented Sep 2, 2014

This comment was originally written by @tatumizer


Somehow, it seems to be fixed in 1.7.0.dev_00_01 (DEV). Please double-check and close.

@mraleph
Copy link
Member

mraleph commented Sep 2, 2014

Florian, can it be fixed by your work on improving polymorphic cases?


cc @fsc8000.

@fsc8000
Copy link
Contributor

fsc8000 commented Sep 3, 2014

Yes, I checked the resulting generated code and the polymorphic inlining of typed data access seems to work as expected now.


Added Fixed label.

@DartBot DartBot added Type-Defect area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. labels Sep 3, 2014
@DartBot DartBot assigned ghost Sep 3, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends.
Projects
None yet
Development

No branches or pull requests

4 participants