Skip to content

Support disabling the Erlang allocator - #357

Open
jearbear wants to merge 1 commit into
elixir-sqlite:mainfrom
jearbear:main
Open

Support disabling the Erlang allocator#357
jearbear wants to merge 1 commit into
elixir-sqlite:mainfrom
jearbear:main

Conversation

@jearbear

@jearbear jearbear commented Aug 22, 2026

Copy link
Copy Markdown

Allow disabling the Erlang allocator which can sometimes have worse performance characteristics compared to the default one as demonstrated in #356.

In addition to the added automated tests, I manually tested this against the repro file provided in the issue by setting my fork as a dependency and toggling the disable_erlang_allocator setting.

Comment thread c_src/sqlite3_nif.c
Comment on lines +1481 to +1484
sqlite3_config(SQLITE_CONFIG_GETMALLOC, &default_alloc_methods);
if (erlang_allocator_enabled) {
sqlite3_config(SQLITE_CONFIG_MALLOC, &methods);
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It seemed simpler to me to unconditionally load and restore the default allocator and only conditionally override the default allocator with the Erlang ones to reduce the amount of branching that needs to happen.

@jearbear

Copy link
Copy Markdown
Author

@warmwaffles I'm a little unsure about the testing story here because it doesn't seem like the existing allocator is tested currently.

Adding the exqlite_erlang_allocator_enabled NIF seemed like an ok middle ground because I want to at least make sure I'm not accidentally reverting the existing default of using the custom allocator. However, it's hard to test the other case easily because the setting can't be changed without restarting the VM so it would require like spawning another test process at least. I tried it out, but it adds to the test runtime and feels pretty hacky.

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