Skip to content

Support disabling the Erlang allocator - #357

Merged
warmwaffles merged 1 commit into
elixir-sqlite:mainfrom
jearbear:main
Aug 24, 2026
Merged

Support disabling the Erlang allocator#357
warmwaffles merged 1 commit into
elixir-sqlite:mainfrom
jearbear:main

Conversation

@jearbear

@jearbear jearbear commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh this is far simpler than what I had originally envisioned. I'll take a closer look at this tomorrow. As it stands I don't see a problem with this.

@jearbear

Copy link
Copy Markdown
Contributor 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.

@warmwaffles

Copy link
Copy Markdown
Member

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

IIRC when I implemented it, it was not tested at all. I could not come up with a reasonable way to test it other than just running the library. However, I do think perhaps running the tests twice would be a solution. One runs with the custom allocator and one without it.

@warmwaffles

Copy link
Copy Markdown
Member

Don't worry trying to figure out how to test the allocator being swapped. I'll spin up a separate task where this is configured to be true or false and run it on CI just to make sure nothing insane is being done with either allocator.

@warmwaffles
warmwaffles merged commit b7da445 into elixir-sqlite:main Aug 24, 2026
9 checks passed
@warmwaffles

Copy link
Copy Markdown
Member

Released under v0.40.0

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