1
votes

A new change detection mechanism was added to AngularDart a few releases ago. I'm trying to write a simple benchmark to compare the new algorithm with the one that was used before.

This is what I came up with:

    class User {
      String firstName;
      String lastName;

      User(this.firstName, this.lastName);
    }

    class Benchmark extends BenchmarkBase {
      TestBed tb;
      Scope s;

      Benchmark(this.tb) : super("Benchmark");

      void warmup() {
        times(20, (_){ tb.rootScope.apply(); });
      }

      void exercise() {
        times(20, (_){ tb.rootScope.apply(); });
      }

      setup() {
        s = tb.rootScope.createChild({});
        times(10000, (i) {
          final user = new User("First ${i}", "Last ${i}");
          s.context["user${i}"] = user;
          s.watch("user${i}.firstName", noop);
        });
      }
    }

I ran this test for Angular 0.9.10 and a similar test for Angular 0.9.4. Surprisingly, Angular 0.9.4 was a bit faster. Is my benchmark too naive?

1
There should be some benchmark code available from the AngualarDart team too. Have you checked the GitHub repo? I read a few discussions about benchmarking the change detection but haven't seen code myself yet (haven't looked for it though).Günter Zöchbauer
@victor-savkin I'm not sure if there really is an issue but first thing I noticed, I don't think running exercise 20 times is enough. You'd probably want to go with at least 2000.markovuksanovic
@markovuksanovic Thanks. After I bumped up the number, the new algorithm got faster than the old one. By not by a lot (around 10%).Victor Savkin
@GünterZöchbauer Thanks, I'll check out the repo.Victor Savkin

1 Answers

1
votes

See our benchmark here: https://github.com/angular/angular.dart/blob/master/perf/watch_group_perf.dart

Your use case should be about the same since theirs case is limited by the speed of field dereference. The real benefit comes for the minimal GC pressure from the new algorithm.