The Gatsby authors annotated each of the three call sites in in-memory/indexing.ts with 'expensive at scale' comments. Their diagnosis is correct: nodeTypeNames.includes(node.internal.type) inside iterateNodes().forEach is O(N*T) per cache build. For N=100k+ nodes typical of mature content sites and T=10-30 declared types per query, this fires on every type-filtered query. gatsby develop in particular rebuilds caches per page render. Fix: hoist Set<string> once at the top of each function. O(1) per node lookup. Total cost O(N+T). Bench shows 8.4x at N=100k T=50; 2.7-4.7x at smaller scales. Three call sites patched: ensureIndexByElemMatch (line 326), ensureEmptyFilterCache (378), ensureIndexByElemMatchValue (504). Author 'expensive at scale' comments updated to record the fix.
6 lines
113 B
Makefile
6 lines
113 B
Makefile
.PHONY: all bench clean
|
|
all: bench
|
|
bench:
|
|
python3 bench/run_all.py
|
|
clean:
|
|
rm -rf bench/__pycache__ __pycache__
|