At least I think it’s near optimal
~if you know how to improve it please do
If you want to learn about BitBuffers, I think this tutorial on how to use stravant’s BitBuffer by TheNexusAvenger is useful
+/- stravant’s bitbuffer:
+nicer API
+stores more compactly
-no innate Roblox userdata support(you shouldn’t be storing them in a BitBuffer though)
+predefined int,uint,short,ushort,etc types
+full float support: inf,-inf,nan,and subnormals
I believe the speed is about the same(fast enough for practical usage if you don’t compute 1000 260k [datastore-valid] character BitBuffers at once-so don’t save all player datas at once, save player one, then wait 5 seconds, etc (and you can even pause while manipulating a single player’s buffer))
Sample usage:
local buff=BitBuffer.New()
buff:UDouble(1/0):Int(123456789):Bool(true):String'Hi'
local s=buff:DataStore()
print(#s)
local buff2=shared.BitBuffer.DataStore(s)
print(buff2:UDouble())
print(buff2:Int())
print(buff2:Bool())
print(buff2:String())
one thing that isnt mentioned here though is that this one uses two’s complement too so it can store 2^(width-1) when using signed numbers (stravants only stores up to 2^(width-1)-1)
One way the api is nicer is that you dont have separate WriteString and ReadString methods (and others), theres just one String method which knows whether to write or read based on how the buffer was instantiated: if it was created from a string(base64,datastore,dump(base256))then its reading the buffer(deserializing) else it writes to the buffer(serializes)