Skip to content

Conversation

@dko-slapdash
Copy link
Contributor

@dko-slapdash dko-slapdash commented Oct 28, 2021

This fixes https://github.com/woutervh-/typescript-is/issues/113

I was debugging the reason of why so many compiled files are changed in our project when a (seemingly unrelated) file change is made, and I found out that typescript-is re-generates the validators code on every change, even when the file isn't changed itself.

Why non-deterministic code generation is a problem? Because the output of tsc may be consumed by other tools (in our case, it's consumed by webpack). So every time something unrelated is changed, webpack has to wake up and do a useless CPU work slowing down everything.

The idea in this PR is to not use type.id directly, but instead have a map of typeId->index inside the context and use that index instead of typeId. Once we see a new typeId, we add a new entry to the map. So in terms of the functionality, this is identical to what we had before, but now the code generated is deterministic.

Before this PR

Screen Shot 2021-10-28 at 12 15 56 PM

Notice that the numbers used in generated function names (_194, _11 etc.) are arbitrary and non-deterministic, so when something in the compilation changes during the watch-mode tsc build, these numbers may drift.

After this PR

Screen Shot 2021-10-28 at 12 16 11 PM

Notice that numbers are now deterministic and start from 0 (e.g. _0, _3).

…n deterministic in watch-mode runs and in recompiles
@woutervh- woutervh- merged commit 1810277 into woutervh-:master Nov 1, 2021
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

Successfully merging this pull request may close these issues.

2 participants