#Sfs

1 messages ยท Page 1 of 1 (latest)

flat wedge
#

If these benchmarks hold true, I'll add this to Express asap

dusk fossil
#

๐Ÿ‘€

west lintel
#

Might sound stupid but is it only able to decode on the same realm as it was encoded? Or am I missing something here?

#
-- CL code snippet
-- tSend is a sequential table
local sEncoded, err, err2 = HG.Core.Serializer.encode(tSend)
if (err) then
  HG.Core.LogError("Serializer", "Error encoding Bodygroups data:", err, err2)
  return
end

net.Start("HG.Network.Bodygroups.Save")
  net.WriteString(sEncoded)
  net.WriteUInt(iSkin, 4)
net.SendToServer()
print("CL:", sEncoded, HG.Core.Serializer.decode(sEncoded))
-- SV code snippet
local sBodygroups = net.ReadString()
local xData, err, err2 = HG.Core.Serializer.decode(sBodygroups)

if (err) then
  HG.Core.LogError("Serializer", "Error decoding data:", err, err2)
  print("SV:", sBodygroups, xData)
  return
end
#

Also, HG.Core.Serializer = include("modules/bin/sh_serializer.lua") is just a shared global for using its methods

old hearth
#

Ur supposed to use writedata not writestring

#

as ur sending binary data

old hearth
#

@flat wedge show ur results too!

old hearth
west lintel
#

yh figured it out, my mind wasn't fully woke up this morning ๐Ÿ˜ญ

#

got really neat results w/ big inventory transfers, congrats!

old hearth
#

can u share them

daring cobalt
old hearth
#

lol

#

its just a simple idea

old hearth
#

kinda sus after adding garrysmod types to the encoder

#

oopsie that was because i had this

#

(still sus)

viral crypt
#

im benchmarking it right now against PON in ULib as ULib sends a lot of small/large tables over

#

seems like pon is smaller for larger files loads

#

pretty significiant too

#

sfs is pretty much faster

#

for anyone wondering im doing this in ULib.clientRPC

old hearth
#

u shouldnt include compress within the test

#

also dont forget to check decode as pon will be way slower

viral crypt
#

i care about the size most tbh

old hearth
#

im kinda curious about what data ur encoding, are they mostly strings

viral crypt
#

i think so yeah, not entirely sure though

#

ill print the table rq

old hearth
#

as im testing rn and for most types except strings sfs is way smaller

#

eg. encoding "true"

#

1 byte in sfs and 4 bytes in pon

#

as pon has to take a table

#
local value_to_encode = {"xd", 3, "play_time", 24759}

sfs 22 pon 30

#

unless ur encoding arrays then ur using a wrong function to do it, and i bet its the case?

viral crypt
#

yeah thats a lot of strings

#

ill dump them to a file

old hearth
#

pon will be smaller in some cases

#

with strings

viral crypt
#
local tbl = {}

for i = 1, 10000 do
    table.insert( tbl, tostring( {} ) )
end

local pc = util.Compress( pon.encode( tbl ) )
print( #pc )

local sc = util.Compress( sfs.encode( tbl ) )
print( #sc )
14883
24153
#

yeah strings are a big difference

#

without the compression

189402
209621
old hearth
#

no the diff here is because of arrays

#

u should use encode_array for arrays

#

and give it the size

viral crypt
#
local tbl = {}

for i = 1, 10000 do
    table.insert( tbl, tostring( {} ) )
end

local p = pon.encode( tbl )
local pc = util.Compress( p )
print( #p, #pc )

local s = sfs.encode_array( tbl, #tbl )
local sc = util.Compress( s )
print( #s, #sc )
188980    24503
180003    22644
old hearth
#

wtf

#

why am i getting diff results

#

are u using a modified pon version

#

wtf why is pon with me giving diff result every time

viral crypt
#

im using 1.2.2

#

tostring will be different in size

#

for me its the same if i use the same table

old hearth
#

thats weird sfs giving me same size?

#

`
sfs 180003
pon 141591

sfs 180003
pon 141744

sfs 180003
pon 139068

`

#

or is it because im testing with luajit directly

#

lemme test with gmod lol

#

bruh why am i getting diff results using luajit directly with pon

#

and why is pon giving smaller/bigger size with same string size

old hearth
viral crypt
#

probably needs ulx too

old hearth
#

i meant the big table, dump it as json

viral crypt
#

๐Ÿ‘

flat wedge
viral crypt
#

gang gang

old hearth
#

god i need a way to figure out if table is an array or not

#

the problem with doing that check is holes

flat wedge
#

if it has holes then it's not an array right

viral crypt
#

yeah

old hearth
#

ye but nil and null

#

undefined

viral crypt
#

gotta loop over the entire table harold

old hearth
#

WHY CANT WE GET ACCESS TO THE ARRAY PART

viral crypt
#

here's the largest chunks

#

and no, i didnt accidentally send that twice ulib seems to do that tf

#

wtf

flat wedge
viral crypt
#

does that have sub tables

flat wedge
#

yes

viral crypt
#

oh i see yeah

flat wedge
#

it doesnt do nonsequential though is the only downside

old hearth
#

bruh sfs will prob win with a really big margin

viral crypt
#

god i hate ulib

old hearth
#

bruh found a bug thanks to gb.randomtable lmfao

viral crypt
#

๐Ÿ‘€

old hearth
#

ok fixed now back to the testing:
pon 215194 compressed: 97651 sfs 134524 compressed: 90841

#
local tbl = gb.RandomTable(10000)

local p = pon.encode( tbl )
local pc = util.Compress( p )
print( "pon", #p, "compressed:", #pc )

local s = sfs.encode( tbl )
local sc = util.Compress( s )
print( "sfs", #s, "compressed:", #sc )
#

ok figured out a way to have support for nested arrays, not 100% accurate for tables with holes but better than having a nested array with no holes get encoded as a table, i noticed that pairs and next always go through the array part then the hash part, so doing next(tbl, #tbl) will tell us if it has a hash value or not (but if it's an array with holes it will be encoded as a hashtable) and thats better than pon's method which prob loops twice and hurts performance for big tables

#

@flat wedge what do u think

old hearth
#

ok tables now get encoded as arrays if they are (not consistent if has holes)

old hearth
# viral crypt

ok i tested all of them and i dont think it's that big difference considering they are all strings, it's the only position where will pon win in size as it uses two bytes to identify it as a string (but it wont win with all strings, some strings will be smaller in size using sfs)

#

but is it worth it if ur just going to use strings? u decide, using ur first big table u sent running 1k times (encode + decode):

#

and dont forget max size int for pon is 32 bit

#

testing using gb.randomtable with 1k fields (encode + decode):

#

prob u wont have to think about it too much lol

viral crypt
#

the speed increase is definitely a big bonus

old hearth
#

ok using a custom type function can make a big perf diff for big tables/arrays

dim storm
#

@old hearth Issue in sfs.table (2 pic)
Result(1 pic) true true
=> test key is missing (4 pic, code 3 pic)

PoC

local tbl = {}
tbl.test1 = "test1"
tbl[#tbl + 1] = {1, 2, 3}
tbl.test2 = "test2"
tbl[#tbl + 1] = {4, 5, 6}
tbl.test3 = "test3"
tbl[#tbl + 1] = {7, 8, 9}

local tbl_len = #tbl
print(tbl_len > 0, next(tbl, tbl_len) == nil)
PrintTable(sfs.decode(sfs.encode(tbl)))
#

The fact check is false-positive or not reliable

dim storm
#

Tomorrow I'll publish it on Git, but that's tomorrow

flat wedge
#

Okay

old hearth
dim storm
dim storm
#

Just another sample

#

More for fun, not serious. So that it would not be possible to say that this is something we have on pure gmod. This check is just as unreliable when running in online Lua interpreters.
https://onecompiler.com/lua/

old hearth
#

yes I can replicate on it, please submit an issue on github so I can check when I have access to my pc

old hearth
#

@dim storm could you test with this check added to the existing checks
next(tbl, tbl_len -1) == tbl_len

dim storm
old hearth
dim storm
#

We'll try to catch it, but it's really much better

old hearth
#

ok