Skip to content

Look up PropNameID names without making a string - #2335

Open
tsapeta wants to merge 3 commits into
meta:static_hfrom
tsapeta:tsapeta/faster-propnameid-creation
Open

tsapeta wants to merge 3 commits into
meta:static_hfrom
tsapeta:tsapeta/faster-propnameid-creation

Conversation

@tsapeta

@tsapeta tsapeta commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

createPropNameIDFromAscii and createPropNameIDFromUtf8 made a string on the GC heap for every call, and then looked it up in the identifier table. For a known name, that string was garbage at once. For a new name, getOrCreateIdentifier copied it into a second string, so the first one was garbage too.

createPropNameIDFromAscii now looks up the name with IdentifierTable::getSymbolID, which makes a string only for a new name. The lookup makes no handles, so the function no longer has a GCScope. createPropNameIDFromUtf8 sends an ASCII name to the same path. Other UTF-8 names use the old code, after the ASCII check, which makes them 0.3% to 1.6% slower on Android.

Time to create a PropNameID and release it, as the median of interleaved runs of the old and new library:

  • macOS: Release build, Apple M2 Pro.
  • Android: Samsung Galaxy A51 (Exynos 9611), pinned to a 2.3 GHz core, with the CMake options of the Gradle release build (MinSizeRel, LTO, HEAP_HV_PREFER32).
  • Known name: "a", already an identifier, also compared with another PropNameID (6 runs). New name: 16 bytes, not an identifier yet, each case in its own process (10 runs).
Call macOS before macOS after macOS change Android before Android after Android change
forAscii, known name 21.6 ns 13.3 ns -38% 168.0 ns 86.4 ns -49%
forUtf8, known name 20.8 ns 15.4 ns -26% 165.6 ns 96.8 ns -42%
forAscii, new name 123.8 ns 119.8 ns -3% ¹ 752.2 ns 646.2 ns -14%
forUtf8, new name 122.9 ns 118.3 ns -4% ¹ 772.1 ns 643.6 ns -17%

¹ Within noise.

Test Plan

  • HermesRuntimeTest.PropNameIDFromAsciiAndUtf8 checks a known name, a new name (with a garbage collection while only the PropNameID refers to it), and a non-ASCII UTF-8 name against the name that JS uses.
  • HermesRuntimeTest.PropNameIDFromUtf8NonAscii puts one non-ASCII character at each position of names of up to 40 characters, which covers each branch of isAllASCII. It also checks invalid UTF-8.
  • Each test fails when the UTF-8 path is broken on purpose.
  • APITests pass in the ASan Debug build.

`createPropNameIDFromAscii` and `createPropNameIDFromUtf8` made a string
on the GC heap for every call, and then looked it up in the identifier
table. When the name was already an identifier, the string was garbage at
once. When the name was new, `getOrCreateIdentifier` copied it into a
second new string, so the first one was garbage too.

`createPropNameIDFromAscii` now looks up the name with
`IdentifierTable::getSymbolID`, which makes a string only for a new name.
`createPropNameIDFromUtf8` sends an ASCII name to the same path.

`PropNameID::forAscii` for a known name goes from 22.6 ns to 16.2 ns, and
`PropNameID::forUtf8` from 21.9 ns to 18.4 ns (Release build, Apple M2
Pro).
@meta-cla meta-cla Bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Nov 21, 2026
@tsapeta
tsapeta deployed to npm-publish November 21, 2026 15:35 — with GitHub Actions Active
`createPropNameIDFromAscii` makes no handles now, so its `GCScope` is not
used:

- `getSymbolID` passes a null handle to `getOrCreateIdentifier`.
- `allocateDynamicString` has its own `GCScope` for a new name.
- `throwPendingError` has its own `GCScope` for an error.

`PropNameID::forAscii` for a known name goes from 15.6 ns to 13.4 ns, and
`PropNameID::forUtf8` from 17.6 ns to 15.3 ns (Release build, Apple M2
Pro).
@tsapeta
tsapeta deployed to npm-publish November 21, 2026 17:52 — with GitHub Actions Active
`createPropNameIDFromUtf8` sends a name to the ASCII path when
`isAllASCII` says that it is ASCII. `isAllASCII` has separate code for
names of up to 4 bytes, up to 16 bytes, and longer names, but the test
had only one short non-ASCII name.

The new test puts one non-ASCII character at each position of names of
up to 40 characters, and checks each name against UTF-16 that the test
builds itself. It also checks a non-ASCII name that JS made first, and
that invalid UTF-8 still stops the name before the first invalid code
point.
@tsapeta
tsapeta deployed to npm-publish November 21, 2026 21:36 — with GitHub Actions Active
@tsapeta
tsapeta marked this pull request as ready for review November 21, 2026 21:36

This branch was successfully deployed

1 active deployment
npm-publish — 4d0666fc Deployed Nov 21, 2026 by tsapeta via publish #1792
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant