mfncooper / mockery

Simplifying the use of mocks with Node.js
Other
1.1k stars 60 forks source link

Increase performance for resetting cache with native modules #47

Closed tidychips closed 8 years ago

tidychips commented 8 years ago

mfncooper/mockery#46 caused some large performance issues as it is unnecessarily checking the cache every time a module is loaded. The check itself does not take long, but the sheer number of times it's called (uselessly) when mocking even a single module can be problematic. When mocking a module that itself has many other imports, this check can be called 100+ times, when it only needed to be called once.

I've moved it so that the cache is only repopulated with native modules when it's reset. This should hopefully allow keeping the fix to mfncooper/mockery#45 while keeping the performance impact to a minimum.

davglass commented 8 years ago

Thanks! Published in mockery@1.6.2