types: optimise ParseTReturn by reading count
and incremental
options
#2095
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.
I have used the
ParseKeys
type to do define some keys that are then passed to at
function and I noticed that when there are a lot of keystypescript
was really slow (similar to #2070).Looking at the types it looks like the bottleneck was
ParseTReturnPlural
.To reduce build time I added the
TOpt
as a new type parameter so all plural and ordinal keys can be computed only when the relative option is provided to thet
function. According to thisParseTReturnPlural
has been divided into two separate types:ParseTReturnPlural
ParseTReturnPluralOrdinal
Each one provide they key for the relevant plural scenario
https://github.com/marcalexiei/i18next/blob/70f498d128ccfdf10a3848981eae05ca548daed5/typescript/t.d.ts#L157-L169
Results
running tic inside the the
many-keys
typescript test scenario produced the following results:Build time was done by ~40%.
In a more simple test scenario like the one of
test:typescript:customtypes
the build time was improved by 5/10%Test machine is a MacBook Pro (15-inch, 2016).
Support JSONFormat v3 in typescript
I added a new test scenario for typescript where JSONFormat v3 (which is the
custom-types
scenario with few key change for plural and ordinal keys).Checklist
npm run test