Bubbles and performance.

Subscribe to Bubbles and performance. 3 posts

avatar for Senekis93 Senekis93 4090 posts
Flag Post

Let’s say you have the following document structure:
A → B → C → D → E → F → G

//in c
d.addEventListener(ev.S,stuff); // ev is (string,true,true)

So… g dispatches ev.S, and reaches d.

Now my question is if it’s necessary to stop propagation or if that function call alone would be more expensive than letting it go all the way up (given that nothing else in the way is awaiting for that particular event)?

Is it completely irrelevant (given a constant use of it)?

 
avatar for player_03 player_03 1249 posts
Flag Post

Try it and see.

Letting it bubble up probably involves additional function calls, but on the other hand, if you’re dealing with enough events to cause lag, you need something more streamlined than Flash’s event handling.

 
avatar for Senekis93 Senekis93 4090 posts
Flag Post

Bah, the point of asking on the forums is so I can be lazy and abuse your knowledge focus on my projects instead of running tests. d:

Anyway, ran a quick test:

1M iterations.

B adds listener to C.
E dispatches it.

A → B → C → D → E

stopPropagation() won by around one second.

I ran further tests with more layers, so it could bubble higher:

A → AA → B → C → D → E
A → AA → AAA → B → C → D → E

The time wasted increased by ~750 ms/layer, which divided by the iterations, gives us an average of 0.00075 extra milliseconds/layer for each event with bubbles which isn’t stopped (in my machine).

Of course, when stopping it, the time remained about the same as in the first test.

Totally irrelevant value, but in case anyone needs to save every possible ns, now you know you have to stop the propagation, especially if the object listening for the event is a bunch of layers down in the list.