| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
getReducedType decided whether an intersection reduces to never by creating the combined property of every property name of every constituent (getPropertiesOfUnionOrIntersectionType). In large intersections most of those synthetic properties, and the intersections of their types, are never used again. Only a combination of distinct constituent properties where one has a literal type (a discriminant), a private property, or a constituent property that is itself such a combination can satisfy isNeverReducedProperty. isNeverReducedIntersection now collects the constituent properties of each name as createUnionOrIntersectionProperty does, including comparing instantiations of the same property, and only creates the combined property for those names. When the properties of the intersection are already resolved it checks them as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Instead of collecting the constituent properties of every name the way createUnionOrIntersectionProperty does, create the combined property for any name that more than one constituent has. The combined property of a name only one constituent has is that constituent's own property, which can only reduce the intersection if it already combines the properties of a union. This creates more combined properties than before, but is much simpler and saves the per-name lookups in every constituent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This reverts d33ab85. The simpler check was faster on the typescript-benchmarking projects, but on a 37k-file program it created 356k more symbols and held 0.28 GiB more heap (about 1.3 GiB more peak RSS with 4 checkers), which is the problem this change is for. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
isNeverReducedIntersection re-implemented how createUnionOrIntersectionProperty collects each constituent's property of a name. That loop is now collectUnionOrIntersectionPropertyParts, and both use it. From what it collects, isNeverReducedIntersection checks whether the combined property could satisfy isNeverReducedProperty (it needs a literal-typed or a private constituent property) before creating it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Max Schwenk (@maschwenk) I have a simpler implementation in #64499 with equally nice results. Thanks much for the research! |
Sorry, something went wrong.
|
Anders Hejlsberg (@ahejlsberg) shall I close this out? |
Sorry, something went wrong.
Yes, #64499 is already in main. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes #64474 (part 2, #64475 is part 1). doesnt depend on #64475
getReducedType checks whether an intersection reduces to never by calling getPropertiesOfUnionOrIntersectionType, which creates the combined property (and the intersection of its types) for every name in the intersection and keeps all of them around. but a combined property can only reduce the intersection if one of the constituent properties has a literal type or is private
so this moves the loop in createUnionOrIntersectionProperty that collects each constituent's property of a name into collectUnionOrIntersectionPropertyParts, and both use it. getReducedType looks at what it collected and only creates the combined property when it could reduce the intersection. theres no second copy of the checking logic. the code change is about 80 lines, the rest of the diff is one test and its baselines
similar goal to #53346, but instead of stopping early it skips creating the properties that can't reduce, which is where the memory goes
this PR alone vs main (typescript-benchmarking, median of 3):
mui-docs gets the big win since its styling types build some really big intersections. the check times on the small projects are within run to run noise. raw results and scripts: https://gist.github.com/maschwenk/c83d9185c6961b6fb43d7d071ef39cf6
i also tried an even simpler check, create the property for any name more than one constituent has (d33ab85). less code, but on our 37k-file program it held 0.28 GiB more heap, so i went back
full go suite passes (also multiple checkers and -race), lint and format are clean. added intersectionNeverReductionByProperty.ts with baselines generated on unmodified main. it covers literal/boolean/template literal discriminants, optional and never props, private vs protected, instantiations of the same generic class, generic aliases and type params with union constraints
used claude code to help write this, ive reviewed it