Skip to content

Reduce repeated work in parallel visitor callbacks #296

Closed

Description

@dexhunter

ParallelVisitor rebuilds callback arguments and visitor indices during each node visit.
This adds overhead when many callbacks do little work.

Situation Before After Change
GitHub schema, 25 empty parallel visitors 195.20 ms 94.48 ms 51.6% less time
GitHub schema validation 46.78 ms 44.11 ms 5.7% less time
Introspection query validation 2.552 ms 2.530 ms Within measurement variation
GitHub schema, one empty visitor 14.28 ms 14.42 ms Within measurement variation

The proposed change builds callback arguments once and stores indices with cached handlers.
It also skips action checks for None results while keeping callback order and behavior unchanged.
The full test suite passes: 3,613 passed, 18 skipped.

Measurements use CPython 3.12.13, Linux x86-64, and an AMD EPYC 9R14.
Both versions ran on the same isolated core with at least 50 rounds per case.
The base commit is f9bdf7c5c728a04bd3f27bfb8d394e9ac95751e2.
The large gain applies to empty callbacks; practical validation benefits are smaller.

Reproduction:

PYTHONPATH=src python -m pytest tests/benchmarks/test_visit.py tests/benchmarks/test_validate_gql.py tests/benchmarks/test_validate_sdl.py --benchmark-enable --benchmark-min-rounds=50

Codex helped prepare and test the proposed change, with candidates tracked through Weco Observe.
We would welcome feedback on this small Python-specific change before opening a pull request.

Activity

  1. changed the title [-]# Reduce repeated work in parallel visitor callbacks[/-] [+]Reduce repeated work in parallel visitor callbacks[/+] on Nov 5, 2026
  2. Cito commented on Nov 5, 2026

    @Cito
    Member

    Closed via #297.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions