Column Compression Extension #5724
cateagle
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I want to use the opportunity of the 0.5.0 release to show off, what I experimented with ever since the commit for the custom types.
I have build a turso extension that uses the custom types to use a simple dictionary compression algorithm to reduce the storage size of TEXT columns without loosing the ability to sort, edit, insert, and delete with the normal TEXT SQL interface. There is some performance overhead of course, but I managed to get it into a usable range. The target use case are short (<256 chars) low entropy TEXT columns like file paths, urls, logs, or enum-like strings. Common compression algorithms struggle to provide meaningful row level compression for this kind of short strings.
You can take a look at it here: https://github.com/cateagle/turso-column-compression
Some features:
Here is usage example to see the general usage (without candidate finding):
For a more complete usage example with compression dictionary management look at https://github.com/cateagle/turso-column-compression/blob/main/tests/prepare_e2e_test.sh
This is still just a proof of concept. It is the first time I have written anything related to compression algorithms so I would not trust production data to my code. I am also still not 100% happy with the way the compression dictionaries are registered and might change the API a little. I would really like to be able to share the compression dictionaries between columns and connect them to the type itself, but that would mean that I would need to handle cross column cross table sampling for the generation of the compression dictionaries.
It would obviously also be great to improve performance as it currently is still nowhere as fast as turso handles TEXT natively, but it has gotten usable already with only being 2-3x slower (depending on the operation). I would be able to achieve significant speed ups with using unsafe to skip the utf-8 validation, but I am too scared to do that for now. Even if I cannot get it to go faster, I still think that there are use cases where the compression could reduce database size by a lot. The theoretical upper limit of compression ratio is 0.0625, but 0.3 to 0.8 is a more realistic expectation.
If someone has any idea of how to improve this or how to better integrate it into turso, I always welcome help or constructive criticism. It is my first time using profiling in rust and I am sure that there are many smarter or more experienced developers than me out there.
All reactions