Fix #113: Make generated function names inside arrow-function deterministic in watch-mode runs and in recompiles #114
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thatindex
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
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
Notice that numbers are now deterministic and start from 0 (e.g.
_0
,_3
).