supertokens-core
supertokens-core copied to clipboard
Using textual UUID doesn't seems to be good idea for performance
🚀 Use binary or optimized UUID for better performance
If we look at this performance test on various ways of storing UUIDs, textual UUID seems to be worst in terms of performance
Implementation details
One way would be using binary form of UUID while storing it in DB using UUID_TO_BIN and BIN_TO_UUID functions. The column type would become binary(16)
which can be better at performance compared to storing UUIDs in a CHAR(36)
column. This is also suggested by this article posted on MySQL Server Blog.
Note: The above mentioned functions,
UUID_TO_BIN
andBIN_TO_UUID
are introduced in MySQL in MySQL 8.0
There is a similar inefficiency using storing UUIDs as text in postgres, well described here.
In brief, storing UUID's using the Text type
select
pg_column_size('00000000-0000-0000-0000-000000000000'::CHAR(36)) char_size,
pg_column_size('00000000-0000-0000-0000-000000000000'::uuid) uuid_size
;
char_size: 40
uuid_size: 16
Or 2.5x as many bytes. It also appears indexes and query performance are quite improved using the smaller representation as well.
Also, using UUID7 instead of UUID4 would be nice: https://www.toomanyafterthoughts.com/uuids-are-bad-for-database-index-performance-uuid7/