Skip to content

Conversation

@dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Jun 17, 2021

For some reason, using an Uint8Array when encoding a string is up to 5x faster. Speedup depends on the browser a bit, but seems to be universal across major engines.

  • I've read the contributing guidelines

@dcodeIO
Copy link
Member Author

dcodeIO commented Jun 17, 2021

Hmm, checked with a larger string now, and it's not anymore. The inconsistency in between browsers is already amazing, but that is strange.

const ptr = __new(size, STRING_ID);

const U16 = new Uint16Array(memory.buffer);
const buf = new Uint8Array(memory.buffer, ptr, size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really faster with ptr and size in constructor? When I last time checked it was less efficient than original approach

@dcodeIO
Copy link
Member Author

dcodeIO commented Sep 4, 2021

There is quite a bit of uncertainty around how and when this is faster. Would probably be best if browsers would just deal with JS strings better. Closing.

@dcodeIO dcodeIO closed this Sep 4, 2021
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.

3 participants