Repository navigation
Commit 2c6629c
committed
Walk the occur fast paths without allocating
Why:
The bounded walks that `occur` and `deep_occur` try first allocated
a ref for their budget and a closure for the walk on every call, and
`iter_type_expr` allocated another closure at each arrow type they
visited. Unification runs `occur` for every variable it links, mostly
on small types, so this allocation was a large share of what the
fast paths cost.
`occur_reaches` and `deep_occur_fast_absent` now walk the type with
mutually recursive functions that take the budget left and return what
remains, following the edges of `iter_type_expr` written out by
constructor. The match on `type_desc` lists every constructor, so a new
one is a compile error here rather than a missed edge. Only
`deep_occur_fast_absent` at a `Tvariant` still goes through
`iter_type_expr` with a closure, for the row's fields. The nodes visited,
the order, the budget and the exceptions raised are unchanged.
Measured with scripts/compilerBenchmarks.js against the previous commit:
allocated words -1.03% in total (-1.14% without the project builds),
stress/TypeAliasChain.res -8.3%, Belt map and set modules -2.7% to
-3.4%. On a 552 module React app (clean build, one domain) the build
allocates 0.99% fewer words. Keeping the closures and only skipping the
walk for a leaf type (a variable or a constructor without arguments)
gave -0.57% in total and -0.54% on the app.
Review: Can a result change? No: a walk that finishes visited exactly
the nodes the closure version visited, within the same budget; one
that gives up still falls back to the full check.
Signed-off-by: Jono Prest <jjprest@gmail.com>1 parent cdafd94 commit 2c6629c
1 file changed
Lines changed: 67 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1423 | 1423 | | |
1424 | 1424 | | |
1425 | 1425 | | |
1426 | | - | |
1427 | | - | |
1428 | | - | |
1429 | | - | |
1430 | 1426 | | |
1431 | 1427 | | |
1432 | | - | |
1433 | | - | |
1434 | | - | |
1435 | | - | |
1436 | | - | |
1437 | | - | |
1438 | | - | |
1439 | | - | |
1440 | | - | |
1441 | | - | |
1442 | | - | |
1443 | | - | |
1444 | | - | |
1445 | | - | |
1446 | | - | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
1447 | 1461 | | |
1448 | 1462 | | |
1449 | 1463 | | |
| |||
1703 | 1717 | | |
1704 | 1718 | | |
1705 | 1719 | | |
1706 | | - | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
1707 | 1752 | | |
1708 | | - | |
1709 | | - | |
1710 | | - | |
1711 | | - | |
1712 | | - | |
1713 | | - | |
1714 | | - | |
1715 | | - | |
1716 | | - | |
1717 | | - | |
1718 | | - | |
| 1753 | + | |
| 1754 | + | |
1719 | 1755 | | |
1720 | 1756 | | |
1721 | 1757 | | |
| |||
0 commit comments