ujjwalguptaofficial / JsStore

Simplifying IndexedDB with SQL like syntax and promises
http://jsstore.net/
MIT License
858 stars 110 forks source link

Tasks overhead #135

Closed olintononthemovesw closed 4 years ago

olintononthemovesw commented 5 years ago

Tasks Overhead

We have been running performance testing on our JsStore queries recently. We've notices that there is quite a significant overhead wasted on creating and destroying Tasks.

image image image

You can see that the actual function call time is reasonably small. Generally it is not a good practice creating an entire Task/Threat for a single functional operation.

I like that JsStore implements Tasks. However, for performance reasons, function calls should be grouped together into a single Task (rather than a Task per function).

Regards,

Osian

olintononthemovesw commented 5 years ago

This data can be found by opening the developer tools (we used google chrome) and selecting the Performance tab. Start recording, then execute some data retrieval using JsStore (the more complicated the better), and stop recording once the result has arrived.

image

olintononthemovesw commented 5 years ago

A solution to this would be to implement the Promise() framework rather than the one for Task(). Difference described here: https://glebbahmutov.com/blog/difference-between-promise-and-task/

As I understand it, running functions as a Task creates a new global execution context.

Just like a Task, a Promise can be chained together, with execution dependants and callbacks. The main difference is that a when a Promise system is used, the global execution context is maintained and only the functional execution context is created/destroyed.

ujjwalguptaofficial commented 5 years ago

We dont use Task api but promise only. Not sure how you are getting task :thinking:

I will look into the performance thing & will share the screenshot here

ujjwalguptaofficial commented 5 years ago

BTW - you can use our idbstudio app for performance testing and share the results publically. Here is the link - https://ujjwalguptaofficial.github.io/idbstudio/

Thanks

olintononthemovesw commented 5 years ago

Tasks are automatically setup when a new global execution context is made. The performance degredation is more easily seen when there are 1000+ records in the tables.

ujjwalguptaofficial commented 5 years ago

What "global execution context" ? Could you point me to some article ?

I am sorry but i am not able to understand what you are saying. As for what you have suggested - we are already using promise api.

Thanks

olintononthemovesw commented 5 years ago

this explains it nicely: https://www.valentinog.com/blog/context/ or this: https://hackernoon.com/execution-context-in-javascript-319dd72e8e2c

essentially, all of the code needs to be kept inside a single 'global' function, while everything else is kept 'in memory' (or added as a dependancy at the very biginning of the global function call)

ujjwalguptaofficial commented 4 years ago

@olintononthemovesw since JsStore is a library its already inside a global function, you cant access JsStore code outside JsStore without calling JsStore.

olintononthemovesw commented 4 years ago

Looks like this problem is actually caused by the base IndexedDb implementation of their Cursor...

Thank you for being an active repository!