garrysmod icon indicating copy to clipboard operation
garrysmod copied to clipboard

net.WriteTable/net.ReadTable and net.ReadEntity/net.WriteEntity improvements

Open meepen opened this issue 10 years ago • 21 comments

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

meepen avatar Oct 12 '15 00:10 meepen

:+1:

bmwalters avatar Oct 12 '15 00:10 bmwalters

You should mention you're also optimizing net.ReadEntity and net.WriteEntity or put it in a different pr

thegrb93 avatar Oct 12 '15 00:10 thegrb93

@willox @robotboy655 @UnderscoreKilburn is there anything in this pr that i could improve or change to make it up to standards and get pulled?

meepen avatar Feb 08 '16 20:02 meepen

In the places you corrected you missed the double/triple indentations. For example line 325 is one tab followed by four spaces.

Bo98 avatar Feb 08 '16 21:02 Bo98

Is it fine now?

meepen avatar Feb 08 '16 21:02 meepen

LGTM

Bo98 avatar Feb 08 '16 22:02 Bo98

Sooooo...?

MyDimeIsUp avatar Jun 16 '16 03:06 MyDimeIsUp

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)

GitSparTV avatar Oct 02 '20 16:10 GitSparTV

Some data structures can be completely dynamic so that assumption is wrong.

thegrb93 avatar Oct 02 '20 17:10 thegrb93

@thegrb93 As would @Kefta say: provide an example of dynamic table that can't be structualized

GitSparTV avatar Oct 02 '20 17:10 GitSparTV

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).

thegrb93 avatar Oct 02 '20 17:10 thegrb93

Even vanilla writetable won't optimize cyclic references

GitSparTV avatar Oct 02 '20 17:10 GitSparTV

Well this enhancement does.

thegrb93 avatar Oct 02 '20 17:10 thegrb93

Why isn't this pulled lmfao.

Swagsson avatar Jan 10 '21 21:01 Swagsson

Quoting code_gs:

I don't really have any interest in improving a function that should just be removed

GitSparTV avatar Jan 24 '21 18:01 GitSparTV

But it won't and can't be removed.

WilliamVenner avatar Oct 09 '21 22:10 WilliamVenner

won't yes can't no

Kefta avatar Oct 10 '21 00:10 Kefta

It can't be removed because it would break thousands of scripts.

WilliamVenner avatar Oct 10 '21 14:10 WilliamVenner

That's why it won't be removed. Doesn't mean it can't

Kefta avatar Oct 10 '21 21:10 Kefta

Irrelevant

WilliamVenner avatar Oct 10 '21 22:10 WilliamVenner

how about improve the thousands of shitty scripts instead of saying "dude it should be removed anyway 🙄🙄" and proceeding to not remove it

Swagsson avatar Oct 12 '21 22:10 Swagsson