New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speed up element data #912
Conversation
…some problems, trying to fix them
…s const char* originally)
assert(szName); | ||
|
||
std::map<std::string, SCustomData>::iterator it = m_Data.find(szName); | ||
CFastHashMap<SString, SCustomData>::iterator it = m_Data.find(szName); | ||
if (it != m_Data.end()) | ||
return &it->second; | ||
|
||
return NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just replace the content of Get
with a call with MapFind
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could but that'd be just a pointless function call, and we can to squeeze out as much performance as we can, and I think this isn't premature optimization(yet)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there will be a real difference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it converting from SString to const char* and then back?
Or it's optimized by the compiler already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
99% chance optimised away. If in doubt, measure the difference
SCustomData* pData = m_pCustomData->Get(szName); | ||
if (pData) | ||
CLuaArgument OldVariable; | ||
if (m_pCustomData->Set(szName, Variable, bSynchronized, &OldVariable)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work correctly if there is no previous element data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, since the original one worked like this as well, it only set a value to CLuaArgument if there was something, otherwise an empty CLuaArgument is == nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR
I just feel like m_SyncedData is so premature optimization... *Edit: yea, its referENCe wrapper, not refernece |
Yeah a few months ago (when we were discussing this in #mta.dev) I thought this looked unnecessary too. I think I looked into removing it, and then realised it was actually necessary. I think? I don't really remember. |
@qaisjp what is #mta.dev? |
#mta.dev is MTA's old IRC channel for development discussions, nowadays it is bridged with our #development Discord channel. |
Whatever you did broke the PR, so I've undone your changes. |
…ors to edata. sub. functions
…asting functions fix CStaticFuncDefs::SyncElementData settings the wrong ElementDataUsage out count.
Add PushArgument(CLuaArgument&&) [reason: obviously, move semantics]. Also remove duplicate code added by git
Nah, its okay, i purposefully Try the test resource from #907. |
I haven't looked at your recent code yet. You can try converting the function to the new lua arg parser, as that apparently speeds stuff up. |
Oh, btw dont belive these failing.. Actually, do, because the client really is, because im a lazy fuck, but the server works fine, just pull the branch, and test it out, I'd be glad, so we can see if there really isnt much of a difference, other than way smaller memory consumption(i made a m_broadcasted, and a m_localOrSubbed maps, so in theory now it should use like 3/4 less memory, because most of the data that is set is synced, and if its synced used to be in both maps, with 2 SCustomData's) |
Uh oh, where can I find that magic? |
Take a look at CLuaBcryptDefs - you'll need to use I think you can use mtasa-blue/Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp Lines 1577 to 1585 in 0ee554b
|
Alright. As it turned out, calling the so, time list(on x64 release server): This PR will help the client way more than the server, because the client is way busier than the server. *10 us on my CPU, take these measurements with a bag of salt, since im pretty sure they arent the most accurate due to the fact |
Made a PR regarding that refactor, so I dont clutter this PR with non-necessary stuff anymore, cuz i did a few things not related to this PR at all. |
Alright, this PR adds no value at all(well, on client-side it does, but I haven't done that yet. I'll leave the server as it is) |
I don't agree, i feel it does add value and it would be a shame to let this effort go to waste. In the case of elementdata, as long we're using it, there aren't many ways to optimize the implementation. I feel like you squeezed the most out of it with these changes, and even if the benefit is just a 20% performance gain, we should take it. It will already make a significant difference in today's climate of scripts (mis)using elementdata massively.. |
The problem with this PR is that is incorporates a lot of changes, that aren't related to it at all(see refactors to other functions I think in CStaticFDs). I'll make an other PR that'll actually be organized, and only contain changes related to it, because rn, reviewing it(let alone merging) is a PITA, IMHO. |
This PR improves element data perfomrnace by 22%(at least for now server-side), I'll implement it client-side as well tomorrow, hopefully.
Renamed the branch so i need a new PR, the old one was #907
Benchmarks can be found @ #907
Test resource