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

Using type parameters can slow down your program with x10 #8972

Closed
larsbak opened this issue Mar 7, 2013 · 3 comments
Closed

Using type parameters can slow down your program with x10 #8972

larsbak opened this issue Mar 7, 2013 · 3 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@larsbak
Copy link

larsbak commented Mar 7, 2013

The code below has been created to measure the impact of using type parameters in "new" expressions. If such a new expression is combined with an "is" check the benchmark is 10 times slower. Please note complex also uses twice the heap memory. Canonicalization or caching of type information is needed to fix this.
//Lars

// Method used Heap VmRSS Runtime
// complex ~320MB 7.2 sec.
// complextWithCheck ~205MB 31.7 sec.
// simple ~154MB 2.6 sec.
// simpleWithCheck ~154MB 3.2 sec.

class B { B(); }
class A<T> { A(); }

class C<S,T> {
  A<T> complex() => new A<T>();

  A<T> complexWithCheck() {
    var a = new A<T>();
    return a is A<T> ? a : a;
  }

  B simple() => new B();

  B simpleWithCheck() {
    var b = new B();
    return b is B ? b : b;
  }
}

main() {
  const int max = 10000000;
  final a = new C<B,B>();
  final c = new List(max);
  for (int i = 0; i < max; i++) c[i] = a.simple();
}

@iposva-google
Copy link
Contributor

Removed the owner.
Added Area-VM label.

@iposva-google
Copy link
Contributor

Removed Priority-Medium label.
Added Priority-Unassigned label.

@larsbak larsbak added Type-Defect area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. labels Jun 5, 2013
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed priority-unassigned labels Feb 29, 2016
@fsc8000
Copy link
Contributor

fsc8000 commented Jan 5, 2017

This can be closed as fixed.

simpleWithCheck:
real 0m1.111s
user 0m1.194s
sys 0m0.236s

complexWithCheck:
real 0m1.176s
user 0m1.278s
sys 0m0.244s

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. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants