sindresorhus / type-fest

A collection of essential TypeScript types
Creative Commons Zero v1.0 Universal
14.41k stars 547 forks source link

Performance regression in Get<> #954

Open panrafal opened 2 months ago

panrafal commented 2 months ago

After updating to the latest version I saw a huge, 50x performance regression in the type that uses Get<> underneath. The difference was measured by typescript tracing.

I don't have a reproduction, but the only commit within the last release that touches this place is this one: https://github.com/sindresorhus/type-fest/commit/986faba1df68e8c4b02f715c2975205b9b07e612 by @Emiyaaaaa

Looking at the change, it's reasonable it caused a slow down, as TS needs to call Path twice now. In my case, the object structure is pretty huge. As extends string[] is much wider, why this is needed?

Upvote & Fund

Fund with Polar

hidemire commented 2 months ago

Hi, we are facing this issue after upgrading from 4.17.0 to 4.26.1. But in our case Get after ~10 minutes of compilation gives error TS2589: Type instanceiation is excessively deep and possibly infinite. error.

import { type Get } from 'type-fest';
import { type EChartsOption } from 'echarts';

type XAxisOptions = Exclude<EChartsOption['xAxis'], Array<unknown> | undefined>;

type Test = Get<XAxisOptions, 'axisLabel'>;
voxpelli commented 2 months ago

Maybe we need to add some performance regression tests as these kind of things are hard to reproduce without a representatively large type graph.

The reasoning for the change in #932 was #863 though – we had inconsistent syntax support between similar types.

@hidemire Can you provide a complete example with tsconfig.json and package.json as well?