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

Make make_binary faster #300

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ruslandoga
Copy link
Contributor

@ruslandoga ruslandoga commented Oct 9, 2024

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).


alias Exqlite.Sqlite3

Benchee.run(
Copy link
Contributor Author

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);
Copy link
Member

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?

Copy link
Contributor Author

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.

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.

2 participants