Skip to content

perf: interpreter block invocation from native iterators #382

Open

Description

@linyiru

Part of #378.

Array#each, #map and #any? over 10 elements (ns per whole call):

each map any?
rubyrs interp 3143 3216 3247
rubyrs tier-2 363 425 403
CRuby 3.4 232 284 251

That is about 290 ns per element in the interpreter, versus about 36 ns under tier-2. The tier-2 path already has a cheap way to call a block from a native iterator. The interpreter does not use it.

This is the largest single interpreter gap: Rails runs 223 block calls per request, and about 40 of them come from Array#each alone.

Do:

  • Profile the interpreter path.
  • Port the tier-2 native-iterator → block call path (or its essence: frame reuse across iterations, no per-yield re-dispatch) to the interpreter, for Array/Hash/Range/Integer iterators first.

Done when:

  • Interpreter each(10) costs ≤ 2× CRuby.
  • No diff_cruby regressions, especially break/next/redo/return-from-block and ensure fixtures.

Activity

  1. added a commit that references this issue on Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions