Repository navigation
Commit b234a39
Remove a union of values from a set in one pass
Removing a UnionType peeled it one member at a time. Peeling is what keeps
the result precise - removing one member can narrow the type so that removing
the next achieves more - but it is quadratic whenever removing a member
rebuilds the from-type, and subtracting a sealed hierarchy from its own type
rebuilds the whole subtraction once per member.
The whole union is now offered first where the subtraction is a set
difference and no order of removals can sharpen it: a sealed hierarchy, or a
union, whose members each weigh the same question again so that a member
needing them one at a time still gets them that way. UnionType::tryRemove()
takes a complete finite value set minus a union of values as one difference,
and ObjectType::subtract() stops normalising a union that changeSubtractedType()
only flattens and throws away - the describe() that keyed the matches goes
with it, an allowed subtype being dropped as it matches so the matches cannot
repeat.
Removing a 250-case enum from its own type: 149ms -> 0.5ms. Removing 125 of
250 constant strings: 6.1ms -> 0.03ms.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LDqrN1pcN3qWc7xzKfkJaF1 parent c2e16da commit b234a39
3 files changed
Lines changed: 157 additions & 41 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| |||
1751 | 1752 | | |
1752 | 1753 | | |
1753 | 1754 | | |
1754 | | - | |
1755 | | - | |
| 1755 | + | |
| 1756 | + | |
1756 | 1757 | | |
1757 | 1758 | | |
1758 | | - | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
1759 | 1773 | | |
1760 | 1774 | | |
1761 | 1775 | | |
| |||
1783 | 1797 | | |
1784 | 1798 | | |
1785 | 1799 | | |
1786 | | - | |
1787 | | - | |
1788 | | - | |
1789 | | - | |
1790 | | - | |
1791 | | - | |
1792 | | - | |
1793 | | - | |
1794 | | - | |
1795 | | - | |
1796 | | - | |
1797 | | - | |
1798 | | - | |
1799 | | - | |
1800 | | - | |
1801 | | - | |
1802 | | - | |
1803 | | - | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
1804 | 1805 | | |
1805 | | - | |
1806 | | - | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
1807 | 1809 | | |
1808 | | - | |
1809 | | - | |
1810 | | - | |
| 1810 | + | |
| 1811 | + | |
1811 | 1812 | | |
1812 | | - | |
1813 | | - | |
1814 | | - | |
1815 | | - | |
1816 | | - | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
1817 | 1828 | | |
1818 | | - | |
1819 | | - | |
1820 | | - | |
| 1829 | + | |
| 1830 | + | |
1821 | 1831 | | |
1822 | | - | |
1823 | | - | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
1824 | 1840 | | |
1825 | | - | |
1826 | | - | |
1827 | 1841 | | |
| 1842 | + | |
| 1843 | + | |
1828 | 1844 | | |
1829 | 1845 | | |
1830 | | - | |
1831 | | - | |
| 1846 | + | |
| 1847 | + | |
1832 | 1848 | | |
1833 | 1849 | | |
1834 | | - | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
1835 | 1864 | | |
1836 | 1865 | | |
1837 | 1866 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
101 | 125 | | |
102 | 126 | | |
103 | 127 | | |
104 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
105 | 143 | | |
106 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
107 | 149 | | |
108 | 150 | | |
109 | 151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
1567 | 1568 | | |
1568 | 1569 | | |
1569 | 1570 | | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
1570 | 1615 | | |
1571 | 1616 | | |
1572 | 1617 | | |
| |||
0 commit comments