Skip to content

perf: use getStringData to avoid UTF-16→UTF-8 re-encoding on decode#51

Open
GrzywN wants to merge 1 commit intocraftzdog:masterfrom
GrzywN:perf/jsi-get-string-data
Open

perf: use getStringData to avoid UTF-16→UTF-8 re-encoding on decode#51
GrzywN wants to merge 1 commit intocraftzdog:masterfrom
GrzywN:perf/jsi-get-string-data

Conversation

@GrzywN
Copy link
Copy Markdown

@GrzywN GrzywN commented Mar 23, 2026

Replace .utf8(runtime) in base64ToArrayBuffer with jsi::String::getStringData, which exposes Hermes's internal string representation directly. Base64 strings are always ASCII, so Hermes stores them as compact byte arrays; the ascii=true branch is a near-zero-overhead copy with no encoding step. The ascii=false fallback handles the UTF-16 case by downcasting each char16_t to char, which is safe because all base64 characters fit in the ASCII range.

Screenshots

Android emulator iPhone 16e simulator

Replace .utf8(runtime) in base64ToArrayBuffer with jsi::String::getStringData, which exposes Hermes's internal string representation directly. Base64 strings are always ASCII, so Hermes stores them as compact byte arrays; the ascii=true branch is a near-zero-overhead copy with no encoding step. The ascii=false fallback handles the UTF-16 case by downcasting each char16_t to char, which is safe because all base64 characters fit in the ASCII range.
@craftzdog
Copy link
Copy Markdown
Owner

thanks for your PRs. I think I can find some time to review them two weeks later.

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.

2 participants