Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slow performance when replacing big modules #340

Closed
slavab89 opened this issue Feb 14, 2018 · 1 comment
Closed

slow performance when replacing big modules #340

slavab89 opened this issue Feb 14, 2018 · 1 comment

Comments

@slavab89
Copy link

When using td.replace on big modules such as request-promise it take a lot of time (almost 1 second!)
I've created a runkit to demostrate this. When i'm running it on my browser it takes around 500ms (which is still a lot for a test i believe)
https://runkit.com/slavab89/5a845a337bdbe50012dea485

When i have a lot of tests that do that logic in BeforeEach, it makes it very slow.

Maybe there should be a possibility to reset only the call counters of all the "when"s somehow?

@searls
Copy link
Member

searls commented Feb 14, 2018

We recommend against using td.replace() to replace 3rd-party dependencies at all, and warn that this is slow.

Personally, I'd recommend isolating most 3rd party dependencies to the periphery of the app by making custom wrappers (i.e. wrap/request-promise.js) that only exports the minimum functions your app uses, potentially translating them to cleaner function signatures that mirror how you design the rest of your code.

I don't think a productive workaround to this would be absorbing some amount of state pollution across test cases to avoid the cost of imitating the dependency (since tracking changes at every single level of a complex replacement would probably cost as much as just re-imitating it, but it'd be an interesting perf optimization experiment)

p.s. Thanks for coming in to ask the question—I hope this reply doesn't read too curtly

@searls searls closed this as completed Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants