Skip to content

Look up PropNameID names without making a string - #2335

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

tsapeta wants to merge 2 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. 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. The lookup makes no handles, so the second commit removes the GCScope from the function. createPropNameIDFromUtf8 sends an ASCII name to the same path. Other UTF-8 names use the old code.

Time to create a PropNameID for a name that is already an identifier, compare it with another PropNameID, and release it. Each value is the median of 6 interleaved runs of the old and new library, and each run takes the median of 15 batches.

  • macOS: Release build, Apple M2 Pro, batches of 1,000,000.
  • Android: Samsung Galaxy A51 (Exynos 9611, Android 13), pinned to a 2.3 GHz core, batches of 200,000. The build uses the CMake options of the Gradle release build (MinSizeRel, LTO, HEAP_HV_PREFER32, HERMES_BUILD_SHARED_JSI), but without fbjni and Intl, so it uses HERMES_UNICODE_LITE.
Call macOS before macOS after macOS change Android before Android after Android change
PropNameID::forAscii(rt, "a") 21.6 ns 13.3 ns -38% 168.0 ns 86.4 ns -49%
PropNameID::forUtf8(rt, std::string("a")) 20.8 ns 15.4 ns -26% 165.6 ns 96.8 ns -42%

Test Plan

  • New HermesRuntimeTest.PropNameIDFromAsciiAndUtf8 creates a PropNameID for a known name, for a new name (with a garbage collection while only the PropNameID refers to it), and for a UTF-8 name that is not ASCII. It checks each one against the name that JS uses. I checked that it fails when the ASCII path for UTF-8 names drops the last character.
  • 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

This branch was successfully deployed

1 active deployment
npm-publish — bd59039d Deployed Nov 21, 2026 by tsapeta via publish #1789
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