Skip to content

Use native base64-bytes conversion utils when they exist#1786

Open
peaBerberian wants to merge 1 commit intodevfrom
base64-native-api
Open

Use native base64-bytes conversion utils when they exist#1786
peaBerberian wants to merge 1 commit intodevfrom
base64-native-api

Conversation

@peaBerberian
Copy link
Collaborator

@peaBerberian peaBerberian commented Jan 20, 2026

To convert between bytes and base64, we previously had a handmade (forked) util because there was no native way of doing it (conversion from and into base64 in the web is done through the HTML API btoa and atob which relies on a JS string for the raw bytes instead of an Uint8Array - probably because those former API predate the latter).

But there's now native API planned (stage 4) in the future ECMAScript 2026 version which does just that, already implemented in most browsers.

Those are operations we may do often:

  • Manifests are text files which most often rely on base64 to include binary data - such as embedded PSSH

  • When persisting persistent license data, if the used storage is text-based (e.g. localStorage), we may also serialize/deserialize a lot of binary data through that util

As such we could profit in terms of performance from relying on native API instead of our JS ones, though the actual impact is difficult to know.


PS: Because this is interesting, I looked at how browsers implemented it:

To convert between bytes and base64, we previously had a handmade
(forked) util because there was no native way of doing it (conversion
from and into base64 in the web is done through the HTML
API `btoa` and `atob` which relies on a JS string for the raw bytes
instead of an `Uint8Array` - probably because those former API predate
the latter).

But there's now [native API planned (stage 4) in the future
ECMAScript 2026](https://github.com/tc39/proposal-arraybuffer-base64)
version which does just that, already implemented in most browsers.

Those are operations we may do often:

-  Manifests are text files which most often rely on base64 to include
   binary data - such as embedded PSSH

-  When persisting persistent license data, if the backed storage is
   text-based, we may also serialize a [lot of binary data through that
   util](https://github.com/canalplus/rx-player/blob/63be19736deafb7c59c8ca671e35c698e77b7c11/src/main_thread/decrypt/utils/serializable_bytes.ts#L36-L45)

As such we could profit in terms of performance from relying on native
API instead of our JS ones, though the actual impact is difficult to
know.
@peaBerberian peaBerberian modified the milestones: 4.4.1, 4.5.0 Jan 20, 2026
@github-actions
Copy link

✅ Automated performance checks have passed on commit 5db818e07fd43488616eaf4c24d5cb234d07d915 with the base branch dev.

Details

Performance tests 1st run output

No significative change in performance for tests:

Name Mean Median
loading 22.93ms -> 23.73ms (-0.800ms, z: 0.32933) 32.25ms -> 32.25ms
seeking 13.34ms -> 16.00ms (-2.664ms, z: 1.42460) 12.75ms -> 12.75ms
audio-track-reload 30.46ms -> 30.37ms (0.090ms, z: 0.15303) 44.70ms -> 44.70ms
cold loading multithread 50.80ms -> 50.10ms (0.702ms, z: 8.47505) 75.00ms -> 73.95ms
seeking multithread 107.07ms -> 108.98ms (-1.907ms, z: 0.15090) 10.95ms -> 11.10ms
audio-track-reload multithread 29.80ms -> 29.65ms (0.150ms, z: 1.97940) 43.95ms -> 43.80ms
hot loading multithread 17.72ms -> 17.57ms (0.152ms, z: 3.23936) 26.00ms -> 25.80ms

@peaBerberian peaBerberian force-pushed the dev branch 9 times, most recently from 0142e34 to 1fd9df3 Compare January 27, 2026 11:59
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.

1 participant