On a quest to learn a bit about Python and sockets I’m writing a little 2d-game server.
And although I don’t see more than a few people on this server at any given time, I want to write it as efficiently as I can.
I have a global dictionary called “globuser”, in it is another dictionary containing the user stats (like the X & Y coordinates)
Is that the best way to store them? How big can a dictionary get?
I guess you could also try to use a regular database, but that would be insanely slow.
Or should I use an entirely different scheme?
Can multiple threads access the same variable at the same time, or are they put on hold?
I guess when lots of users are on-line, every move would require an update. If they can happen at the same time, great! But if they each require to “lock” the variable, that would be less great.
One thing I might look at is storing the users as a list of
Playerobjects. Look into__slots__, as that will save you memory when creating many instances.I also would not worry much about performance at this stage. Write the code first and then run it through a profiler to find out where it is slowest — making blind changes in the name of optimization is bad juju.
Regarding thread safety and sharing of data, I found this, which seems to give some info on the subject.