garrysmod
                                
                                
                                
                                    garrysmod copied to clipboard
                            
                            
                            
                        net.WriteTable/net.ReadTable and net.ReadEntity/net.WriteEntity improvements
After all the drama of the last pr, I thought I'd rewrite it to make it more clean and add some tests to my local machine.
Here's my test: https://gist.github.com/meepdarknessmeep/421640b80568c51eb5f9 All these pass should pass without any errors.
Some profiling:
[1.00000,   1.00000,    1.00000,    1.00000]
[1.00000,   1.00000,    1.00000,    1.00000]
[1.00000,   1.00000,    1.00000,    1.00000]
[1.00000,   1.00000,    1.00000,    1.00000]
recursive1  true
recursive2  true
2=2 true
0
1   =   a
2   =   b
3   =   true
4   =   3.14
7   =   1.000000 2.000000 3.000000
8   =   3.000 4.000 2.000
cc  =   cc
q   =   [1.00000,   1.00000,    1.00000,    1.00000]
[1.00000,   1.00000,    1.00000,    1.00000]
[1.00000,   1.00000,    1.00000,    1.00000]
[1.00000,   1.00000,    1.00000,    1.00000]
t:
        1   =   a
        2   =   b
        3   =   true
        4   =   3.14
        7   =   1.000000 2.000000 3.000000
        8   =   3.000 4.000 2.000
        cc  =   cc
        q   =   [1.00000,   1.00000,    1.00000,    1.00000]
[1.00000,   1.00000,    1.00000,    1.00000]
[1.00000,   1.00000,    1.00000,    1.00000]
[1.00000,   1.00000,    1.00000,    1.00000]
        t   =   table: 0x3a706f48
107.25
1
1:
        1   =   a
        2   =   b
        3   =   true
        4   =   3.14
        7   =   1.000000 2.000000 3.000000
        8   =   3.000 4.000 2.000
        cc  =   cc
        q   =   [1.00000,   1.00000,    1.00000,    1.00000]
[1.00000,   1.00000,    1.00000,    1.00000]
[1.00000,   1.00000,    1.00000,    1.00000]
[1.00000,   1.00000,    1.00000,    1.00000]
        t   =   table: 0x3a707dc8
108.75
2
2   =   2
3   =   3
4.14141414  =   4.14141414
16.875
So the lengths of the three table sent in bytes is (in order) 107.25, 108.75, 16.875 Most of the bits come from net.*Matrix itself.
The old output is:
recursive1  false   stack overflow
recursive2  false   stack overflow
2=2 true
2
2   =   2
3   =   3
4.14141414  =   4.14141414
The first two tests fail because of recursion, and the last test is larger than the new WriteTable
:+1:
You should mention you're also optimizing net.ReadEntity and net.WriteEntity or put it in a different pr
@willox @robotboy655 @UnderscoreKilburn is there anything in this pr that i could improve or change to make it up to standards and get pulled?
In the places you corrected you missed the double/triple indentations. For example line 325 is one tab followed by four spaces.
Is it fine now?
LGTM
Sooooo...?
Optimizing WriteTable doesn't have sense for me. You can always find the structure of your data and send it with more optimized for you way. Also you have some flaws in concatenation, it's better to use a table and then table.concat (talking about string7 or string6)
Some data structures can be completely dynamic so that assumption is wrong.
@thegrb93 As would @Kefta say: provide an example of dynamic table that can't be structualized
Ones with cyclic references. Sure you can number the table references yourself and make it net friendly, but that's what writeTable should do. (Though I'm pretty sure gmod's vanilla writeTable doesn't).
Even vanilla writetable won't optimize cyclic references
Well this enhancement does.
Why isn't this pulled lmfao.
Quoting code_gs:
I don't really have any interest in improving a function that should just be removed
But it won't and can't be removed.
won't yes can't no
It can't be removed because it would break thousands of scripts.
That's why it won't be removed. Doesn't mean it can't
Irrelevant
how about improve the thousands of shitty scripts instead of saying "dude it should be removed anyway 🙄🙄" and proceeding to not remove it