RBS scan cache to improve overall performance - #1796
Conversation
Context#add_alias can append methods or attributes as a side effect, making mutation-side cache updates depend on Context internals. Index each collection's unconsumed tail during lookup instead, keeping synchronization in one place while preserving linear lookup.
|
I agree that the quadratic cost should be fixed. However, it also happens in the normal RDoc parse path, not just RBS. It would be simpler to implement the cache in Context itself rather than in each parser. Making Context already has a hash-based lookup: Concretely, we could add internal methods like
|
|
I will revisit this PR once #1802 will be merged. |
RBS parsing repeatedly searched growing method and attribute arrays, making classes with many declarations quadratic. This replaces those searches with parser-local Hash indexes while leaving the ordered code-object collections unchanged.
The indexes are initialized from existing context members and updated when methods, attributes, or aliases are added. This preserves behavior for rebuilt stores, forward aliases, and legacy instance methods with a nil singleton value.
Five measured runs with 2,000 declarations per workload:
Benchmark
https://gist.github.com/skatkov/82f89eaf2269286a42a4adf966d2fd12