Skip to content

[cpp] Optimise Bytes.ofString utf8#12585

Open
tobil4sk wants to merge 1 commit into
HaxeFoundation:developmentfrom
tobil4sk:fix/cpp-optimize-Bytes.ofString
Open

[cpp] Optimise Bytes.ofString utf8#12585
tobil4sk wants to merge 1 commit into
HaxeFoundation:developmentfrom
tobil4sk:fix/cpp-optimize-Bytes.ofString

Conversation

@tobil4sk

@tobil4sk tobil4sk commented Feb 9, 2026

Copy link
Copy Markdown
Member

To use the current Utf8.encode method, we have to run getByteCount which iterates through the string to create a buffer which is the right size. However, since Utf8.encode is a public function, it has to validate that the size of the buffer is correct, which means it iterates through the string again.

This new Utf8.encode method without a buffer argument creates its own array and returns it, avoiding the unnecessary check.

This requires the method to be added to hxcpp: HaxeFoundation/hxcpp#1306.

@tobil4sk tobil4sk force-pushed the fix/cpp-optimize-Bytes.ofString branch from 8d03e4c to 0bb8417 Compare March 26, 2026 10:53
To use the current Utf8.encode method, we have to run getByteCount which
iterates through the string to create a buffer which is the right size.
However, since Utf8.encode is a public function, it has to validate that
the size of the buffer is correct, which means it iterates through the
string again.

This new Utf8.encode method without a buffer argument creates its own
array and returns it, avoiding the unnecessary check.
@tobil4sk tobil4sk force-pushed the fix/cpp-optimize-Bytes.ofString branch from 0bb8417 to 4f4d81f Compare July 8, 2026 12:59
@tobil4sk

tobil4sk commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

@Simn @Aidan63 this is the haxe std side fix corresponding to HaxeFoundation/hxcpp#1306, and it will hopefully further improve performance for the text related benchmarks.

The hl failure is likely related to HaxeFoundation/hashlink@b0c568a, and should disappear on ci rerun.

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