-
Notifications
You must be signed in to change notification settings - Fork 48
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
Make make_binary faster #300
base: main
Are you sure you want to change the base?
Conversation
f0ae237
to
6dfdf63
Compare
999a6d3
to
5194aa0
Compare
|
||
alias Exqlite.Sqlite3 | ||
|
||
Benchee.run( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The benchmark will be removed before merging.
|
||
return term; | ||
ERL_NIF_TERM bin; | ||
const char* data = enif_make_new_binary(env, size, &bin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I didn't use this function because of the documentation: https://www.erlang.org/doc/apps/erts/erl_nif.html#enif_make_new_binary
The drawbacks are that the binary cannot be kept between NIF calls and it cannot be reallocated.
Is this saying that we shouldn't store it in a global static ERL_NIF_TERM
and that it should be safe to pass back to the VM but don't rely on it being present?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that's what it means. I'm pretty sure it's safe to use since Exqlite only keeps conn and stmt resources between nif calls.
According to the docs this version would try to allocate small binaries on the process heap, which seems to positively affect benchmarks (xqlite uses this approach).