Commit 09d060f
authored
[ty] Memoize binary operator return types (#24700)
## Summary
Especially for cases like astral-sh/ty#3039,
we were running binary operator inference over and over, and throwing
away everything except the return type. This PR adds a cached query for
_just_ the return type, which is more lightweight than storing the
entire `Bindings` but seemingly still very effective.
For:
```python
import pandas as pd
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]})
df["d"] = df["a"] + df["b"] + df["c"] + 1 + (df["a"] ** 2 + df["b"] ** 2 + df["c"] ** 2)
```
Codex reports a 3.32x speedup. Repeating that expression 20 times, Codex
reports a 50.79x speedup (from 52.471s down to 1.033s).
Closes astral-sh/ty#3039.1 parent a494065 commit 09d060f
2 files changed
Lines changed: 48 additions & 41 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
14 | 37 | | |
15 | 38 | | |
16 | 39 | | |
| |||
Lines changed: 25 additions & 41 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
450 | 450 | | |
451 | 451 | | |
452 | 452 | | |
453 | | - | |
454 | | - | |
455 | | - | |
| 453 | + | |
456 | 454 | | |
457 | 455 | | |
458 | 456 | | |
| |||
483 | 481 | | |
484 | 482 | | |
485 | 483 | | |
486 | | - | |
487 | | - | |
488 | | - | |
| 484 | + | |
489 | 485 | | |
490 | 486 | | |
491 | 487 | | |
| |||
511 | 507 | | |
512 | 508 | | |
513 | 509 | | |
514 | | - | |
515 | | - | |
516 | | - | |
| 510 | + | |
517 | 511 | | |
518 | 512 | | |
519 | 513 | | |
| |||
524 | 518 | | |
525 | 519 | | |
526 | 520 | | |
527 | | - | |
528 | | - | |
529 | | - | |
530 | | - | |
531 | | - | |
532 | | - | |
533 | | - | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
540 | 531 | | |
541 | 532 | | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
555 | 543 | | |
556 | 544 | | |
557 | 545 | | |
| |||
854 | 842 | | |
855 | 843 | | |
856 | 844 | | |
857 | | - | |
858 | | - | |
859 | | - | |
| 845 | + | |
860 | 846 | | |
861 | 847 | | |
862 | 848 | | |
| |||
1039 | 1025 | | |
1040 | 1026 | | |
1041 | 1027 | | |
1042 | | - | |
1043 | | - | |
1044 | | - | |
| 1028 | + | |
1045 | 1029 | | |
1046 | 1030 | | |
1047 | 1031 | | |
| |||
0 commit comments