Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS/JS] Create byte vectors #8185

Merged
merged 3 commits into from
Dec 19, 2023
Merged

Conversation

razvanalex
Copy link
Contributor

Flatbuffers supports creating byte vectors from native byte objects in some languages (e.g., Go, Python, Swift, Java).
This PR brings createByteVector to TypeScript, which is similar to createString except it does not add the null terminator and does not require UTF-8 encoded data.

Also, the performance for createString method could be improved (see below) if instead of using for loop we use set, since the buffer is a Uint8Array. Larger gains can be seen when creating large byte vectors. Set is used also here, so the change would not break any previous compatibility requirements.

Here is a gist with the benchmarking code. I used node v18.16.1.

Results before the change:

BenchmarkCreateString/1 0.016412479999999997 ms
BenchmarkCreateString/10        0.00312446 ms
BenchmarkCreateString/100       0.0065587 ms
BenchmarkCreateString/1000      0.039675659999999995 ms
BenchmarkCreateString/10000     0.27408254 ms
BenchmarkCreateString/100000    0.19494983999999999 ms
BenchmarkCreateString/1000000   1.3230981599999998 ms
BenchmarkCreateString/10000000  11.25195066 ms
BenchmarkCreateString/100000000 148.96931926 ms
BenchmarkCreateString/1000000000        1361.0493652799998 ms

real    1m16.644s
user    0m55.069s
sys     0m22.605s

Results after the change:

BenchmarkCreateString/1 0.01656288 ms
BenchmarkCreateString/10        0.0027338599999999994 ms
BenchmarkCreateString/100       0.00389304 ms
BenchmarkCreateString/1000      0.00394246 ms
BenchmarkCreateString/10000     0.03633938 ms
BenchmarkCreateString/100000    0.1101002 ms
BenchmarkCreateString/1000000   0.4885558 ms
BenchmarkCreateString/10000000  2.8422376 ms
BenchmarkCreateString/100000000 57.1328341 ms
BenchmarkCreateString/1000000000        511.0220611 ms

real    0m29.061s
user    0m8.405s
sys     0m21.822s

@razvanalex
Copy link
Contributor Author

It seems the failure of labeler action is related to this.

@dbaileychess dbaileychess enabled auto-merge (squash) December 19, 2023 06:39
@dbaileychess dbaileychess merged commit c0d1699 into google:master Dec 19, 2023
jochenparm pushed a commit to jochenparm/flatbuffers that referenced this pull request Oct 29, 2024
* Add createByteVector and use set in createString

* Add test for CreateByteVector

---------

Co-authored-by: Derek Bailey <derekbailey@google.com>
jochenparm pushed a commit to jochenparm/flatbuffers that referenced this pull request Oct 29, 2024
* Add createByteVector and use set in createString

* Add test for CreateByteVector

---------

Co-authored-by: Derek Bailey <derekbailey@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants