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

Performance improvements via simplifying and optimizing event emitter #117

Closed
wants to merge 1 commit into from

Conversation

lukemelia
Copy link
Contributor

This includes:

  • Removed support for multiple eventnames from on and off.
  • Removed defensive code around duplicate event registrations.
  • Removing an event removes all handlers for that event name --
    there is no longer a way to remove a specific event handler.
  • Optimized object shape for the event target mixin.

These changes are all in the service of performance. We used
a slightly modified version of cujojs/promise-perf-tests to
benchmark, which runs in node. We've attached them below.

@stefanpenner / @lukemelia

~

> promise-perf-tests@0.3.2 test /Users/lmelia/p/promise-perf-tests
> ./bin/run.sh

==========================================================
Test: promise-fulfill x 10000
----------------------------------------------------------
Name      Time ms   Avg ms   Diff %
when           26   0.0026        -
q              43   0.0043    65.38
rsvp PR        90   0.0090   246.15
rsvp master    94   0.0094   261.54

==========================================================
Test: promise-reject x 10000
----------------------------------------------------------
Name      Time ms   Avg ms   Diff %
q              38   0.0038        -
when           48   0.0048    26.32
rsvp PR        66   0.0066    73.68
rsvp master   100   0.0100   163.16

==========================================================
Test: promise-sequence x 10000
----------------------------------------------------------
Name      Time ms   Avg ms   Diff %
when           82   0.0082        -
q             191   0.0191   132.93
rsvp PR       240   0.0240   192.68
rsvp master   411   0.0411   401.22

==========================================================
Test: defer-create x 100000
----------------------------------------------------------
Name      Time ms   Avg ms   Diff %
rsvp PR        76   0.0008        -
when          208   0.0021   173.68
q             243   0.0024   219.74
rsvp master   276   0.0028   263.16

==========================================================
Test: defer-fulfill x 10000
----------------------------------------------------------
Name      Time ms   Avg ms   Diff %
when           85   0.0085        -
rsvp PR       120   0.0120    41.18
rsvp master   206   0.0206   142.35
q             247   0.0247   190.59

==========================================================
Test: defer-reject x 10000
----------------------------------------------------------
Name      Time ms   Avg ms   Diff %
when           80   0.0080        -
rsvp PR       131   0.0131    63.75
rsvp master   203   0.0203   153.75
q             228   0.0228   185.00

==========================================================
Test: defer-sequence x 10000
----------------------------------------------------------
Name      Time ms   Avg ms   Diff %
when          127   0.0127        -
rsvp PR       214   0.0214    68.50
q             291   0.0291   129.13
rsvp master   433   0.0433   240.94

This includes:

* Removed support for multiple eventnames from `on` and `off`.
* Removed defensive code around duplicate event registrations.
* Removing an event removes all handlers for that event name --
  there is no longer a way to remove a specific event handler.
* Optimized object shape for the event target mixin.

These changes are all in the service of performance. We used
a slightly modified version of cujojs/promise-perf-tests to
benchmark, which runs in node. We've attached them below.

@stefanpenner / @lukemelia

~
````
> promise-perf-tests@0.3.2 test /Users/lmelia/p/promise-perf-tests
> ./bin/run.sh

==========================================================
Test: promise-fulfill x 10000
----------------------------------------------------------
Name      Time ms   Avg ms   Diff %
when           26   0.0026        -
q              43   0.0043    65.38
rsvp PR        90   0.0090   246.15
rsvp master    94   0.0094   261.54

==========================================================
Test: promise-reject x 10000
----------------------------------------------------------
Name      Time ms   Avg ms   Diff %
q              38   0.0038        -
when           48   0.0048    26.32
rsvp PR        66   0.0066    73.68
rsvp master   100   0.0100   163.16

==========================================================
Test: promise-sequence x 10000
----------------------------------------------------------
Name      Time ms   Avg ms   Diff %
when           82   0.0082        -
q             191   0.0191   132.93
rsvp PR       240   0.0240   192.68
rsvp master   411   0.0411   401.22

==========================================================
Test: defer-create x 100000
----------------------------------------------------------
Name      Time ms   Avg ms   Diff %
rsvp PR        76   0.0008        -
when          208   0.0021   173.68
q             243   0.0024   219.74
rsvp master   276   0.0028   263.16

==========================================================
Test: defer-fulfill x 10000
----------------------------------------------------------
Name      Time ms   Avg ms   Diff %
when           85   0.0085        -
rsvp PR       120   0.0120    41.18
rsvp master   206   0.0206   142.35
q             247   0.0247   190.59

==========================================================
Test: defer-reject x 10000
----------------------------------------------------------
Name      Time ms   Avg ms   Diff %
when           80   0.0080        -
rsvp PR       131   0.0131    63.75
rsvp master   203   0.0203   153.75
q             228   0.0228   185.00

==========================================================
Test: defer-sequence x 10000
----------------------------------------------------------
Name      Time ms   Avg ms   Diff %
when          127   0.0127        -
rsvp PR       214   0.0214    68.50
q             291   0.0291   129.13
rsvp master   433   0.0433   240.94
````
@stefanpenner
Copy link
Collaborator

Likely more to come, as we still clearly have some head room. We should also get some jsperf tests going, as the browsers are very important platforms for us.

@stefanpenner
Copy link
Collaborator

With some twiddling to event subscription I have promise fulfillment nearly as fast as when, and rejection faster then when. This slightly improves sequence.

Experimentation shows by essentially removing event emitter, and using a different mechanisms, we can get on-par or slightly faster then when. But I am unsure about the micro optimizations (that I propose in this comment) vs code quality tradeoff. Interestingly the "extra" cost that we seem to be seeing is really in the subscription itself. Not the emitting.

@stefanpenner
Copy link
Collaborator

likely superseeded by #132 which stops using the event emitter itself for internal promise uses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants