Description
Bug Report
π Search Terms
Slow, enums, large. Related issue that looks similar: #42824
π Version & Regression Information
Not sure when this started. I'm testing on 5.0.4
- This is a performance problem
β― Playground Link
Playground link with relevant code
π» Code
The code is in the playground link. The exact tsconfig.json that I'm testing with is:
{
"compilerOptions": {
"target": "ES2022",
"module": "commonjs",
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
π Actual behavior / π Expected behavior
The code in the playground link has an enum containing 753 values and contains the following ITest
interface:
interface ITest {
transforms?: PartialRecord<ItemType, ItemType>;
}
where PartialRecord
is defined at the top of the file as:
export type PartialRecord<K extends number, V> = { [key in K]?: V };
Running a trace build / analyze results in:
PS Z:\Data\Downloads\test> tsc --generateTrace tstrace && npx analyze-trace tstrace --forceMillis 100
Hot Spots
ββ Check file z:\data\downloads\test\index.ts (259ms)
ββ Check variable declaration from (line 777, char 11) to (line 777, char 61) (189ms)
ββ Check expression from (line 777, char 20) to (line 777, char 61) (186ms)
The hotspot is line 777 - const target = items[itemType1]?.transforms?.[itemType2];
Now if I change the ITest
interface to the following:
interface ITest {
transforms?: { [key in ItemType]?: ItemType };
}
(I'm essentially using the same typing that PartialRecord<ItemType, ItemType>
provides)
The performance is improved now, it's 2.5x faster. The self-time for the expression on line 777 went from 171ms to 66ms -
PS Z:\Data\Downloads\test> tsc --generateTrace tstrace && npx analyze-trace tstrace --forceMillis 100
Hot Spots
ββ Check file z:\data\downloads\test\index.ts (153ms)
My codebase has a lot of large enums, so this matters quite a bit to us in the overall scheme of things.
Is it possible to speed up the typing in the case when we use something like PartialRecord
with large enums?