Repository navigation
Conversation
`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).
`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).
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
createPropNameIDFromAsciiandcreatePropNameIDFromUtf8made 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,getOrCreateIdentifiercopied it into a second new string, so the first one was garbage too.createPropNameIDFromAsciinow looks up the name withIdentifierTable::getSymbolID, which makes a string only for a new name. The lookup makes no handles, so the second commit removes theGCScopefrom the function.createPropNameIDFromUtf8sends an ASCII name to the same path. Other UTF-8 names use the old code.Time to create a
PropNameIDfor a name that is already an identifier, compare it with anotherPropNameID, 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.MinSizeRel, LTO,HEAP_HV_PREFER32,HERMES_BUILD_SHARED_JSI), but without fbjni and Intl, so it usesHERMES_UNICODE_LITE.PropNameID::forAscii(rt, "a")PropNameID::forUtf8(rt, std::string("a"))Test Plan
HermesRuntimeTest.PropNameIDFromAsciiAndUtf8creates aPropNameIDfor a known name, for a new name (with a garbage collection while only thePropNameIDrefers 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.APITestspass in the ASan Debug build.