Skip to content

Optimize type equality fast paths#11420

Open
bschnurr wants to merge 1 commit intomicrosoft:mainfrom
bschnurr:perf/is-type-same-fastpaths
Open

Optimize type equality fast paths#11420
bschnurr wants to merge 1 commit intomicrosoft:mainfrom
bschnurr:perf/is-type-same-fastpaths

Conversation

@bschnurr
Copy link
Copy Markdown
Member

@bschnurr bschnurr commented May 7, 2026

Summary

This optimizes isTypeSame by avoiding recursive comparisons when two types share the same immutable backing structures. The fast paths cover shared class type arguments, shared function parameter metadata, shared overload arrays, shared union subtype arrays, and shared TypeVar bound/constraint structures.

Details

The change keeps the existing structural comparison behavior for non-shared data, but skips recursive walks when reference identity proves the relevant backing structure is identical. This commonly applies to shallow-cloned or decorated types.

Validation

  • npm run test:norebuild -- --runTestsByPath src/tests/typeEquality.test.ts --forceExit
  • npm run build

Performance Notes

On a local full-project NumPy CPU profile, isTypeSame self time dropped from about 21.98s to 19.02s (-13.5%) after these fast paths. A sampled heap profile did not show the edited helper functions as allocation sites. Whole-program wall-clock timing remains noisy, so this PR is presented as a targeted hotspot reduction rather than a claimed end-to-end throughput win.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Copy Markdown
Collaborator

@rchiodo rchiodo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved via Review Center.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants