Skip to content

perf: avoid empty effect argument arrays - #1023

Merged
domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/effect-empty-args-981
Sep 9, 2026
Merged

domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/effect-empty-args-981

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Pass the existing effect argument value directly to Function.prototype.apply. An undefined argument list already means zero callback arguments, so no temporary empty array is needed.
  • Preserve the null callback receiver, explicit positional dependency values, current callbacks, and their paired cleanups across insertion, layout, and passive effects.
  • Add a production helper allocation guard and a patch changeset for octane.

Partially addresses #981's effect-dispatch item. Hook-map membership checks remain necessary for cleared or rolled-back slots; this PR does not change those checks or specialize callback arities.

Performance evidence

Baseline: merged main 9b17f4e2899e1bec886e8577197d40429f006c48. Same Node 26.4.0 / V8 14.6.202.34-node.21, production transform, workload, and observer for both revisions:

BENCH_JSON=/tmp/effect-dispatch.json node benchmarks/effectful-list/dispatch.mjs 9b17f4e
Argument list Effects Source array creations before After
Omitted 3,000 3,000 0
Explicit empty array 3,000 0 0
Three explicit values 3,000 0 0

The guard extracts the actual runtime helper by AST and observes it after production transformation. Clean and observed runs agree on callback arguments/receiver, cleanup, phase/depth restoration, stale-entry rejection, and errors. The zero-array guard fails on the baseline. These are source array-creation events at the helper boundary, not measured heap allocations or application latency: an optimizing engine may already eliminate the temporary array.

Both rebuilt production effectful-list fixtures (TSRX and TSX) also passed all six existing lifecycle/DOM gates with three iterations. Their explicit dependency arrays are negative controls; no timing improvement is claimed.

Validation

  • Targeted runtime suite: 22 files, 218 tests passed, including dev/prod hooks, conditional hooks, effect dispatch/timing/order/deletion, insertion effects, error handling, Suspense effects, and deferred/production hydration.
  • New behavior matrix: undefined, null, empty, and 1–4 dependency values across all three phases. Deliberately replacing the null receiver with undefined made all 14 new dev/prod cases fail, then the implementation was restored and final tests passed.
  • pnpm typecheck:files packages/octane/src/runtime.ts
  • Scoped pnpm format:files:check for all six changed files and git diff --check
  • pnpm sync (no generated changes)
  • Paired dispatch work guard and production TSRX/TSX browser lifecycle controls
  • Full repository pnpm test, pnpm typecheck, and pnpm format:check were not run locally for this bounded runtime change. Current-head CI passed all 26 jobs on 9fe7ce2f9198500f4af9d678797b0f0421c5fdad, including lint, typechecking, all runtime and React parity shards, browser integration, package validation, and examples. Cursor Bugbot completed successfully with no findings; there are no review threads to resolve.

Risk / follow-ups

The runtime change adds no state, caches, branching, or retained references. Existing slot/publication guards, exception routing, and cleanup handling are unchanged. SSR does not execute effect bodies. Independent diff review found no correctness issues. The remaining effect-dispatch ideas in #981 need separate correctness and performance evidence.

Provenance

  • An agent produced this diff (agent-authored)

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Low Risk
Single-line runtime dispatch change with broad new tests and a regression guard; no auth, data, or scheduling logic changes beyond argument passing semantics.

Overview
Effect dispatch no longer allocates a temporary empty array when an effect has no dependency list: runEffectBody passes e.args straight into apply instead of (e.args ?? []), relying on undefined meaning zero positional arguments.

Adds an untimed allocation guard (benchmarks/effectful-list/dispatch.mjs) that AST-extracts the production runEffectBody, instruments array literals, and asserts zero creations for omitted/empty/value dependency cases (with optional baseline compare). Documents it in the effectful-list README and records an octane patch changeset.

Tests add EffectArguments and a matrix over undefined/null/empty and 1–4 deps for insertion, layout, and passive effects—checking null this, positional args, cleanup pairing, and re-fire rules (empty [] does not re-run on update).

Reviewed by Cursor Bugbot for commit 9fe7ce2. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Sep 9, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review September 9, 2026 18:31
@domgan-oai
domgan-oai merged commit 7804852 into octanejs:main Sep 9, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant