-
-
Notifications
You must be signed in to change notification settings - Fork 718
Huge performance drop when having thousands calls to factory which resolves singletone dependencies #423
Description
So, i have a project https://github.com/javascript-obfuscator/javascript-obfuscator/tree/dev and now i'm trying to move it on Inversify.
Inside some class i have code that traverses over AST tree (nodes) and for each node calls factory which returns array of node obfuscators for this node.
Without Inversify performance tests are returns following results:
- 500 runs of program - ~8 sec total.
- run with very large code size - ~1.8 sec.
With Inversify i got huge performance drop:
- 500 runs of program - ~28 sec total.
- run with very large code size - 5-6 sec.
With Inversify i created factory which resolves and returns instances of node obfuscators.
All instances are bind in singletone scope.
Now code examples.
Old code:
Factory call when traversing through ast tree
https://github.com/javascript-obfuscator/javascript-obfuscator/blob/dev/src/Obfuscator.ts#L116
Factory itself
https://github.com/javascript-obfuscator/javascript-obfuscator/blob/dev/src/node-transformers/AbstractNodeTransformersFactory.ts#L38
With Inversify
Factory call when traversing through ast tree
https://github.com/javascript-obfuscator/javascript-obfuscator/blob/inversify/src/Obfuscator.ts#L147
Factory itself
https://github.com/javascript-obfuscator/javascript-obfuscator/blob/inversify/src/container/InversifyContainerFacade.ts#L64
Binding setup for classes which factory is resolve
https://github.com/javascript-obfuscator/javascript-obfuscator/blob/inversify/src/container/modules/NodeObfuscatorsModule.ts#L15
So i'm doing something wrong?
Expected Behavior
Small performance drop.
Current Behavior
Huge performance drop.
Steps to Reproduce (for bugs)
You can clone this two branches
https://github.com/javascript-obfuscator/javascript-obfuscator/tree/dev
https://github.com/javascript-obfuscator/javascript-obfuscator/tree/inversify
then npm i && npm test
latest two asserts are performance asserts.