Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implements +rb_shape_get_iv_index_with_hint: a version of rb_shape_get_iv_index which uses a previous shape with a valid index for the given IV in order to speed up searches on a IV inline cache miss. This works by walking up both the hint shape's and current shape's tree branches in parallel until they meet at a common ancestor. The thinking behind this is that in many cases we have different, but very similar shapes, but who share the common ancestor defining the IV we're looking for. This should also work well for a frozen version of a shape. This is significantly faster when the divergence between the current and hint shape is shallow, but when it is not (there is no relation between the two shapes) it still resorts to a linear scan. The full scan is slower with this, as more work is being done, but I believe not 2x slower (the LL means we'll be stalling all the time on memory so walking two lists in parallel isn't _so_ bad). Benchmark: https://gist.github.com/jhawthorn/e9db7a1443eaa957cef772dccdc14d9a With a shallow tree divergence before: ruby --disable-gems test_shape_search.rb 1.64s user 0.00s system 99% cpu 1.648 total after: ./miniruby test_shape_search.rb 0.67s user 0.00s system 99% cpu 0.666 total With a deep tree divergence (assumed uncommon) before: ruby --disable-gems test_shape_search_deep.rb 1.64s user 0.00s system 99% cpu 1.643 total after: ./miniruby test_shape_search_deep.rb 1.88s user 0.01s system 99% cpu 1.889 total
- Loading branch information