Skip to content

FE-1528: Skip combination enumeration for token-independent lambdas - #9389

Merged
kube merged 5 commits into
mainfrom
cf/fe-1528-skip-combination-enumeration-for-lambdas-that-read-no-input
Sep 3, 2026
Merged

FE-1528: Skip combination enumeration for token-independent lambdas#9389
kube merged 5 commits into
mainfrom
cf/fe-1528-skip-combination-enumeration-for-lambdas-that-read-no-input

Conversation

@kube

@kube kube commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Before this PR, a lambda's only per-combination input is the token attributes it reads. When it reads none, its rate is the same for every combination. Engine still enumerated every combination for such a lambda, evaluating the same rate C(n, w) times per frame.

Engine draws one acceptance uniform per transition per frame and fires the first passing combination, so either the first combination fires or none does. Testing only the first combination is therefore exact: same RNG stream, same consumed tokens, meaning the first w in place order, same trajectories for every seed. Measured on benchmarks/coloured-enumeration.mjs with a never-firing weight-2 arc, per run-frame:

Case Before (token-reading lambda, enumerates) After (token-independent lambda)
50 tokens 40 µs 0.7 µs
400 tokens 2 543 µs 0.9 µs (flat)

Before the lazy enumeration of FE-1526, the eager implementation cost 13.8 ms per run-frame on the 400-token case.

Links

Changes

Core

  • analyzeHir marks token-independent lambdas readsNoInputTokens

    Set on the compiled artifact when the lambda reads no token attributes or counts and is deterministic; analyzeHir already tracks token reads.
    Artifacts compiled before the field existed keep enumerating.

  • Both engines test only the first combination when the flag is set

    A single first-combination marking replaces the enumerator; loop bodies are untouched. Engine-supplied constant lambdas, for transitions with no lambda code, take the same path.

Benchmarks

  • benchmarks/coloured-enumeration.mjs gains a token-independent case

    Existing cases now read a token so they keep measuring enumeration.

Next steps

WebGPU pair scan could use the same flag to skip its unranking loop.

Test coverage

  • hir/artifacts.test.ts:

    readsNoInputTokens on compiled artifacts: set for constant and parameters-only lambdas, absent when the lambda reads token attributes or a token count, or draws randomness.

  • simulation/engine/compute-possible-transition.test.ts:

    One lambda call instead of C(4,2), first tokens consumed, identical RNG state and outcomes against the enumerating path.

  • simulation/monte-carlo/token-independent-lambda.test.ts:

    End-to-end seeded run with identical results when the flag is stripped.

How to test

  • turbo run build test:unit --filter '@hashintel/petrinaut-core'
  • cd libs/@hashintel/petrinaut-core
  • node benchmarks/coloured-enumeration.mjs, imports from ../dist
  • Expect token-independent case near 1 µs per run-frame from 50 to 400 tokens
  • Expect token-reading cases growing with token count

@kube kube self-assigned this Aug 27, 2026
@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hash Ready Ready Preview Sep 3, 2026 2:12pm UTC
petrinaut Ready Ready Preview Sep 3, 2026 2:12pm UTC
petrinaut-docs Ready Ready Preview Sep 3, 2026 2:12pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
hashdotdesign-tokens Ignored Ignored Preview Sep 3, 2026 2:12pm UTC

Request Review

@github-actions github-actions Bot added area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team type/eng > backend Owned by the @backend team labels Aug 27, 2026
@kube
kube force-pushed the cf/fe-1528-skip-combination-enumeration-for-lambdas-that-read-no-input branch from 5ce29d2 to 1067f0d Compare August 30, 2026 13:08
@kube
kube force-pushed the cf/fe-1528-skip-combination-enumeration-for-lambdas-that-read-no-input branch from 1067f0d to 0a6a63f Compare September 1, 2026 23:17
@kube
kube force-pushed the cf/fe-1528-skip-combination-enumeration-for-lambdas-that-read-no-input branch from 0a6a63f to 24bc08d Compare September 2, 2026 15:04
@kube
kube force-pushed the cf/fe-1528-skip-combination-enumeration-for-lambdas-that-read-no-input branch from 24bc08d to 195a080 Compare September 2, 2026 16:12
@kube
kube marked this pull request as ready for review September 2, 2026 18:31
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a manual request Sep 3, 2026
@kube
kube dismissed YannisZa’s stale review September 3, 2026 12:31

The merge-base changed after approval.

@kube
kube requested a review from a team as a code owner September 3, 2026 12:31
TimDiekmann
TimDiekmann previously approved these changes Sep 3, 2026

@TimDiekmann TimDiekmann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-approval of pre-rebase

@kube
kube force-pushed the cf/fe-1528-skip-combination-enumeration-for-lambdas-that-read-no-input branch from 44f7ccb to 1bf9cc4 Compare September 3, 2026 13:03
@kube
kube requested a review from TimDiekmann September 3, 2026 13:03
TimDiekmann
TimDiekmann previously approved these changes Sep 3, 2026
@kube
kube added this pull request to the merge queue Sep 3, 2026
Base automatically changed from cf/fe-1526-enumerate-weighted-arc-token-combinations-lazily-in-the to main September 3, 2026 16:16
Merged via the queue into main with commit db73020 Sep 3, 2026
158 of 184 checks passed
@kube
kube deleted the cf/fe-1528-skip-combination-enumeration-for-lambdas-that-read-no-input branch September 3, 2026 16:17
@hash-release hash-release Bot mentioned this pull request Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > backend Owned by the @backend team type/eng > frontend Owned by the @frontend team

Development

Successfully merging this pull request may close these issues.

4 participants