p-kuen / PatchProtect

A Prop Protection for Garry's Mod
12 stars 10 forks source link

get rid of net.WriteTable #123

Open 60percentCaffeine opened 8 years ago

60percentCaffeine commented 8 years ago

get rid of net.WriteTable as it's inefficient and definitely not lagfree, net.WriteType is poor too, don't use it

d-kuen commented 8 years ago

Hi, why do you know, that net.Write* is that inefficient? Any statistics or somewhat?

If these functions are inefficient, what should we use instead? I can remember that some gmod-developers made major changes on net.Write* to make them more efficient.

60percentCaffeine commented 8 years ago

@Domii894 Internally net.WriteTable uses net.WriteType that writes UInt in addition to value that indicates type of a value (in table). Looking at the code I can say that you pretty much can use other net library functions for networking. It's the biggest bottleneck in this addon as far as I can say.

60percentCaffeine commented 8 years ago

@Domii894 Oh I just understood you have misunderstood me. There is a net.WriteType function, that writes ANY type you need, but it sends an additional UInt (number) that indicates type of a value in addition to the value you need to send. net.WriteTable uses it and it has some inefficient things in it too, so it should be avoided.

d-kuen commented 8 years ago

@uRandomAlex No, i got what you said and checked the implementation of net.WriteTable and found out what you were talking of.

I think the most simple fix would be while loops with net.Write* and net.Read*, because almost every table-row we send has the same type.

As I also said to other ppl, I/we am/are very busy at the moment and don't have time to fix this. It will likely a short and easy fix, but that it too much too (currently don't even have gmod installed :P). Maybe someone else makes a pull-request or I/we will do it some time later. :)

storm37000 commented 4 years ago

im pretty sure the write table is best for cpu efficiency but less for network, turning the table into json, compressing, sending the compressed data, decompressing, and un json on the other side would be more cpu intensive but save network. also looping would be probably the worst on the cpu.