-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Additional checks for unsigned integers to avoid underflow and overflow #3197
Conversation
Note the potential performance impact as mentioned by Mark. |
This implementation causes performance to be compromised, in fact it drops by about 70%~ You can try the following code and you can compare the time, you will notice that with this implementation increases the time dramatically. time_t now = OTSYS_TIME();
for (int i = 0; i < 1000000000; i++) {
getNumber<time_t>(L, 2);
}
std::cout << "Test getNumber of LuaInterface: " << std::setprecision(15) << (double)(OTSYS_TIME() - now) << std::endl; I know that there are never cases in which |
@MillhioreBT are you testing with release version all optimizations enabled? |
Of course, the code is clear to the naked eye, obviously it takes more time, but it wouldn't be a big problem really, since at small scales there doesn't seem to be a much difference. |
It would be amazing to have the opinion of @marksamman about this |
Is it dropping performance in general or is it with invalid value only? |
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.
imo not worth losing 70% of the performance for that. Should be optional in compiler settings.
The test conducted by @MillhioreBT is synthetic, not representative of what datapacks in the wild do. |
Follow-up to otland#3926 and otland#3197. Co-authored-by: Daniel Speichert <daniel@speichert.pl>
Additional checks in getNumber(L, arg)
Prints a handy warning if unsigned integer is negative or exceeds the max number for defined type.