question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RFC: Leverage --incremental

See original GitHub issue

This is a feature request.

Issue

Our team is working on a large codebase and we are currently having issues with the time our CI takes. We are looking at all the ways to make the build faster. One of the bottlenecks is the time it takes to run the tests. We investigated and most of time taken to run unit tests is not to actually run the tests but to compile the TS files on-the-fly.

Expected behavior

The thing is that TS files have already been compiled as part of the build step. We would love for ts-jest to leverage this and rely on them.

One idea is to have ts-jest write the compiled files on disk and leverage the incremental option. As ts-jest attempts to recompile the code, tsc will see that most of the work was already done.

We understand this is a large undertaking and I am ready to help! From a quick glance I already identified ts-jest performs additional transformation to hoist jest.mock() and that could be a challenge.

Alternatives

We found none of the speed-up alternatives to be satisfying. They are:

  • Compile the test files ahead of time. It works great but we lose snapshots and it’s a poor developer experience. Not a good fit.
  • Compile with babel instead of ts-jest. It’s still slow, it doesn’t support all of TypeScript features, the TDD experience is not as good and the code that is tested in not the one that actually runs in production. Not a good fit.

We would largely prefer to stick with ts-jest but performance improvements are really necessary for us. Again, I’m ready to work on it.

What do you think about this feature, and would you support a PR introducing it?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:45
  • Comments:27 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
ahnpnlcommented, Feb 18, 2020

FYI, perhaps later we can learn from Angular CLI regarding to this topic.

@yacinehmito I managed somehow to use create incremental program for ts-jest but I’m not sure if I did it correctly. If you have time, would you please help me to check my experiment ? You can find it on this branch. I made a folder called compiler and you can look into program.ts.

To run the experiment codes, ts-jest config needs to have

"experimental": true,
"compilerHost": true

and tsconfig needs to have incremental: true

3reactions
yacinehmitocommented, Jan 3, 2020

I did after you told me about this. Thank you for the info.

It confirms the level of coupling. I did a PoC of a runner with support for --incremental and it turned out to be a bit slower than ts-jest. With ts-jest, what we lose in speed by not using --incremental, we gained thanks to its aggressive caching.

The issue is that it’s this very caching that makes us stop using ts-jest. We have quite a large TypeScript project (almost 300k lines of code) and ts-jest completely chokes on it. Even with a v8 set at 4GB of RAM it blows up. The culprit is the in-memory cache. We are relying on our PoC instead.

The PoC is less smart than ts-jest and a bit more hacky: it’s a runner combined with a transformer. The runner first compiles the project on disk with --incremental. Because it’s a runner it happens only once; there are no concurrent compilation. Then the transformer, instead of compiling the TS files, will just read the compiled JS file from disk, so it’s quite fast.

In the end we ended up with something that is just slightly slower than ts-jest but simpler to reason about and with no pressure on the RAM.


The biggest challenge for the introduction of incremental in ts-jest is the TypeScript transformer to hoist calls of jest.mock. If we implement it naïvely, we might end up with running test files that were already on disk because they didn’t build as part of a jest run, hence not having the hoisted jest.mock calls.


Takeaway: I don’t think I’ll be working on that feature for now. Sorry.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Planning for Change with RFCs - Increment
Learn how requests for comments (RFCs) can help software development teams make more informed and egalitarian technical decisions.
Read more >
Wireline Incremental IPv6 RFC 6782 - IETF Datatracker
Wireline Incremental IPv6 (RFC 6782, November 2012) ... The operator may be able to leverage one or the other protocol to help bridge...
Read more >
RFC Debtors Unit Issuance Ratio Definition - Law Insider
Debt to Capital Ratio means the ratio (expressed as a percentage) of debt to total capital (the sum of debt and equity). This...
Read more >
Tim on Twitter: "Incremental Adoption is at the core of this RFC ...
Incremental Adoption is at the core of this RFC, given the deep implications that ... By migrating your application you'll also be able...
Read more >
[LLVMdev] [RFC] LCSSA vs. SSAUpdater ... FIGHT! - Google Groups
Require LCSSA form input, leverage its (very powerful) guarantees to ... and use powerful incremental SSA formation utilities built on SSAUpdater to form ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found