Skip to content

perf(js): stop allocating buffers for each F32 bit cast - #1643

Open
oxura wants to merge 4 commits into
bendlang:mainfrom
oxura:perf/js-f32-bitcasts-20261017
Open

oxura wants to merge 4 commits into
bendlang:mainfrom
oxura:perf/js-f32-bitcasts-20261017

Conversation

@oxura

@oxura oxura commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1638.

The JS bit casts share a four-byte buffer instead of allocating one for every call. They reuse the cast functions from bend.ts, with no second implementation or endian flags.

Kept the round-trip table for signed zero, subnormals, finite bounds and infinities; removed the unrelated lib.bits(0.75) call. No new NaN-payload guarantee.

Local generated-module smoke: 0 / 16777216. Repo gate: 54/54. The maintainer ran the full gates on the previous head; I haven’t rerun the private gates locally.

@Lorenzobattistela Lorenzobattistela self-assigned this Oct 19, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@Lorenzobattistela Lorenzobattistela left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks! The speedup is real and all gates are green. I pushed a commit that drops the GUIDE edit; we don't want that change in the guide. Three small things before we merge:

  1. Don't duplicate the bend.ts helpers. bend.ts already has these exact casts: F32_VIEW, f32_to_bits and f32_from_bits. comp.ts already splices ${Bend.f32_round} into the JS runtime, so reuse the bend.ts versions the same way instead of keeping a second copy in comp.ts.
  2. Drop the , true arguments. Each cast writes and reads with the same byte order, so the little-endian flag changes nothing. Big-endian, the default that bend.ts uses, gives the same bits. The four arguments just cost ttok in comp.ts.
  3. Remove lib.bits(0.75) from the test loop. It can't catch a scratch-reuse bug: value is already a JS number before that call, and lib.bits(value) rewrites the buffer before reading it. The round-trip table on its own is the useful part.

@oxura

oxura commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

This is JS-only performance work, so I’m withdrawing it following the reference-runtime policy in #1644.

@oxura oxura closed this Oct 19, 2026
@oxura oxura reopened this Oct 19, 2026
@oxura

oxura commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

I closed this too quickly after reading #1644 — sorry. Reopening it and taking care of these three points.

@oxura

oxura commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Done — comp.ts now splices in the two bend.ts helpers and uses their default byte order. Dropped the extra test call. The exported-module smoke passes (0 / 16777216), and the repo gate is 54/54.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JS F32 bit casts allocate a fresh buffer and typed views on every call

2 participants