Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ever used `SQLite_OMIT_*` directives to reduce SQLite's memory footprint?
2 points by tester457 on Aug 25, 2023 | hide | past | favorite | 4 comments
I recently came across a section in the book "Using SQLite" by Jay A. Kreibich where he mentions[1] the `SQLITE_OMIT_*` compile-time directives.

> Using the default configuration, the compiled SQLite library is less than 700 KB on most platforms, and requires less than 4 MB of memory to operate. By omitting the more advanced features, the library can often be trimmed to 300 KB or less. With minor configuration changes, the library can be made to function on less than 256 KB of memory, making its total footprint not much more than half a megabyte

While this sounds promising, I'm struggling to find any discussions or blog posts on the use of these directives. Has anyone here tried them?

[1] https://www.oreilly.com/library/view/using-sqlite/9781449394592/apas08.html



Yes, I've used them quite extensively. They work. There's not really much that I found in terms of gotchas about them, as long as you are aware of whether or not you actually need something you're wanting to omit. Sometimes you do when you don't think you do.


Good to know! Which of the omit directives do you usually use?


It has varied quite a lot depending on the exact application. The use case is so that you can embed SQLite directly in the executable rather than using an external server. You're almost certainly using the DBMS for a very specific thing, and it's usually clear what features your application will never use. So you omit them, not only in order to minimize size, but also to flag if the code accidentally uses something surprising on a later modification.

What I've frequently done when approaching this in a new project is to omit the stuff that's obviously unneeded, then go though and start omitting everything else (that isn't obviously needed) one at a time, performing a regression test each time to learn if it needs to be put back.

I think my most common directives have been SQLITE_OMIT_DECLTYPE, SQLITE_OMIT_DEPRECATED, and SQLITE_OMIT_SHARED_CACHE. But I've used much more than that.

If you're optimizing to this degree, there are other directives that may be of interest to you as well. For instance, I'm often used SQLITE_THREADSAFE=0 when thread safety was a nonissue.

See this page: https://www.sqlite.org/compile.html

Oh, I think it's also best practice to put all of the compile-time directives in a separate header file so they're all in one place and aren't cluttering up the rest of the code.


Thank you!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: