xaviergonz / mobx-keystone

A MobX powered state management solution based on data trees with first class support for Typescript, support for snapshots, patches and much more
https://mobx-keystone.js.org
MIT License
549 stars 25 forks source link

Slowness actionTrackingMiddleware #440

Open hersentino opened 2 years ago

hersentino commented 2 years ago

Hello,

I made an example branch (https://github.com/hersentino/mobx-keystone-issue/tree/middleware) which shows that actionTrackingMiddleware has some slowness even if onStart/onEnd do nothing. Just calling it takes about 25ms. 50 ms if the data passed in parameter to the modelAction are big. The problem is if I call modelAction inside modelAction n times it can significantly impact the global performance.

Do you have an idea explaining these durations ?

Thanks :)

xaviergonz commented 2 years ago

is the repo public? I get a 404

hersentino commented 2 years ago

I'm sorry, I made a mistake, I've just edited the url

xaviergonz commented 2 years ago

it takes longer because you are measuring the detachment of the old big tree as part of the instantiation of the new small tree

if you add

    this.setMainModel(undefined);

after each setMain model you will see the following results instead:

With big data
time of instanciation with fromGrpc without middleware : 789.8999999910593 ms
time of instanciation with fromGrpc with middleware : 854.8999999910593 ms
time took by the middleware 65 ms

With small data
time of instanciation with fromGrpc without middleware : 0.29999999701976776 ms
time of instanciation with fromGrpc with middleware : 0.8999999910593033 ms
time took by the middleware 0.5999999940395355 ms