Duistere Pluizenbal on Nostr: I often struggle to disable the micro-optimization-addicted part of my brain when ...
I often struggle to disable the micro-optimization-addicted part of my brain when designing SQL schemas.
VNDB has a table with 4 enum columns, each supporting 5-6 possible values. Postgres encodes enums as 4 bytes, so those 4 columns occupy 16 bytes on disk. But the same information would comfortably fit in just 2 bytes!
Of course, I could merge the columns into a single smallint with some fancy bit twiddling, but that comes at the cost of awkward queries and complicating the codebase. The benefits aren't worth it either: space savings will likely be insignificant if you factor in other columns and row overhead, and it's unlikely to make much of a difference in terms of performance.
BUT STILL THAT INFORMATION COULD BE 8 TIMES SMALLER!

Published at
2024-12-22 08:33:34Event JSON
{
"id": "47cf6b14e33b769c07022ad51e17f3cf35d91e420a41b564354b40bb665763e1",
"pubkey": "6dd915cc3f1f20f651a99b566c7c1ebb34a071a820f113b9aaf419c346b0e37d",
"created_at": 1734856414,
"kind": 1,
"tags": [
[
"emoji",
"blobcatreeeeeee",
"https://files.lonely.town/custom_emojis/images/000/000/168/original/67a960ab531c7f4c.png"
],
[
"proxy",
"https://lonely.town/users/ayo/statuses/113695549996388400",
"activitypub"
]
],
"content": "I often struggle to disable the micro-optimization-addicted part of my brain when designing SQL schemas.\n\nVNDB has a table with 4 enum columns, each supporting 5-6 possible values. Postgres encodes enums as 4 bytes, so those 4 columns occupy 16 bytes on disk. But the same information would comfortably fit in just 2 bytes!\n\nOf course, I could merge the columns into a single smallint with some fancy bit twiddling, but that comes at the cost of awkward queries and complicating the codebase. The benefits aren't worth it either: space savings will likely be insignificant if you factor in other columns and row overhead, and it's unlikely to make much of a difference in terms of performance.\n\nBUT STILL THAT INFORMATION COULD BE 8 TIMES SMALLER! :blobcatreeeeeee:",
"sig": "6a0172b276ffc1f72d0d86f5f7f6cf9598c4869d376188904cc6a0fab6afba7246c5fc43e9d96a8e87430b48627f7e60c765280a8f580dbbf7378a83a0d22bd3"
}