Commit 5275791
authored
Cache native grammar on parser grammar object (#387)
## Summary
- add one explicit `WP_Parser_Grammar::$native_grammar` cache slot
- store the compiled Rust grammar on the PHP grammar object instead of
in a content-hash cache
- remove the full exported-grammar hash walk from native parser
construction
## Why
The previous Rust-only content-key cache preserved a smaller PHP diff,
but every parser construction still exported and recursively hashed the
entire grammar before it could hit cache. In the SQLite smoke benchmark
that dropped the native path back to roughly 2x faster than PHP.
This restores the object-attached cache path we had before, but keeps
the PHP diff explicit and minimal: one new public cache property on
`WP_Parser_Grammar`.
## Measurements
Command:
```bash
TMP_TEST_NATIVE_QUERY_COUNT=250 ./tmp-test-native/run.sh
```
| Run | PHP parser | Rust parser | Speedup |
| ---: | ---: | ---: | ---: |
| 1 | 3.088s | 0.389s | 7.94x |
| 2 | 3.126s | 0.386s | 8.10x |
| 3 | 2.927s | 0.348s | 8.41x |
Default 2000-query smoke workload:
| Workload | PHP parser | Rust parser | Speedup |
| --- | ---: | ---: | ---: |
| 2000 generated queries, including 8 x 2000-row inserts | 24.082s |
3.008s | 8.01x |
## Testing
- `cargo fmt --check`
- `php -l
packages/mysql-on-sqlite/src/parser/class-wp-parser-grammar.php`
- `git diff --check`
- `TMP_TEST_NATIVE_QUERY_COUNT=250 ./tmp-test-native/run.sh`
- `./tmp-test-native/run.sh`
## Notes
This assumes `WP_Parser_Grammar` is immutable after construction for
native parsing purposes. That matches current use, and the tradeoff is
isolated in this PR so it is visible in review.1 parent 80d8a64 commit 5275791
2 files changed
Lines changed: 36 additions & 138 deletions
File tree
- packages
- mysql-on-sqlite/src/parser
- php-ext-wp-mysql-parser/src
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
915 | 915 | | |
916 | 916 | | |
917 | 917 | | |
918 | | - | |
919 | | - | |
920 | | - | |
921 | | - | |
922 | | - | |
923 | | - | |
924 | 918 | | |
925 | 919 | | |
926 | 920 | | |
| |||
930 | 924 | | |
931 | 925 | | |
932 | 926 | | |
933 | | - | |
934 | | - | |
935 | | - | |
936 | | - | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
937 | 932 | | |
938 | 933 | | |
939 | 934 | | |
| |||
1685 | 1680 | | |
1686 | 1681 | | |
1687 | 1682 | | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
1688 | 1687 | | |
1689 | 1688 | | |
1690 | 1689 | | |
1691 | 1690 | | |
1692 | 1691 | | |
1693 | 1692 | | |
1694 | 1693 | | |
1695 | | - | |
1696 | | - | |
1697 | | - | |
1698 | | - | |
1699 | | - | |
1700 | | - | |
1701 | | - | |
1702 | | - | |
1703 | | - | |
1704 | | - | |
1705 | 1694 | | |
1706 | 1695 | | |
1707 | 1696 | | |
| |||
1751 | 1740 | | |
1752 | 1741 | | |
1753 | 1742 | | |
1754 | | - | |
1755 | | - | |
1756 | | - | |
1757 | | - | |
1758 | | - | |
| 1743 | + | |
1759 | 1744 | | |
1760 | 1745 | | |
1761 | 1746 | | |
1762 | 1747 | | |
1763 | | - | |
1764 | | - | |
1765 | | - | |
1766 | | - | |
1767 | | - | |
1768 | | - | |
1769 | | - | |
1770 | | - | |
1771 | | - | |
1772 | | - | |
1773 | | - | |
1774 | | - | |
1775 | | - | |
1776 | | - | |
1777 | | - | |
1778 | | - | |
1779 | | - | |
1780 | | - | |
1781 | | - | |
1782 | | - | |
1783 | | - | |
1784 | | - | |
1785 | | - | |
1786 | | - | |
1787 | | - | |
1788 | | - | |
1789 | | - | |
1790 | | - | |
1791 | | - | |
1792 | | - | |
1793 | | - | |
1794 | | - | |
1795 | | - | |
1796 | | - | |
1797 | | - | |
1798 | | - | |
1799 | | - | |
1800 | | - | |
1801 | | - | |
1802 | | - | |
1803 | | - | |
1804 | | - | |
1805 | | - | |
1806 | | - | |
1807 | | - | |
1808 | | - | |
1809 | | - | |
1810 | | - | |
1811 | | - | |
1812 | | - | |
1813 | | - | |
1814 | | - | |
1815 | | - | |
1816 | | - | |
1817 | | - | |
1818 | | - | |
1819 | | - | |
1820 | | - | |
1821 | | - | |
1822 | | - | |
1823 | | - | |
1824 | | - | |
1825 | | - | |
1826 | | - | |
1827 | | - | |
1828 | | - | |
1829 | | - | |
1830 | | - | |
1831 | | - | |
1832 | | - | |
1833 | | - | |
1834 | | - | |
1835 | | - | |
1836 | | - | |
1837 | | - | |
1838 | | - | |
1839 | | - | |
1840 | | - | |
1841 | | - | |
1842 | | - | |
1843 | | - | |
1844 | | - | |
1845 | | - | |
1846 | | - | |
1847 | | - | |
1848 | | - | |
1849 | | - | |
1850 | | - | |
1851 | | - | |
1852 | | - | |
1853 | | - | |
1854 | | - | |
1855 | | - | |
1856 | | - | |
1857 | | - | |
1858 | | - | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
1859 | 1760 | | |
1860 | | - | |
| 1761 | + | |
1861 | 1762 | | |
1862 | 1763 | | |
1863 | | - | |
1864 | | - | |
1865 | | - | |
1866 | | - | |
1867 | | - | |
1868 | | - | |
1869 | | - | |
1870 | | - | |
1871 | | - | |
1872 | | - | |
1873 | | - | |
1874 | | - | |
1875 | | - | |
1876 | | - | |
1877 | | - | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
1878 | 1774 | | |
1879 | 1775 | | |
1880 | 1776 | | |
| |||
2028 | 1924 | | |
2029 | 1925 | | |
2030 | 1926 | | |
| 1927 | + | |
2031 | 1928 | | |
2032 | 1929 | | |
2033 | 1930 | | |
| |||
0 commit comments