-
-
Notifications
You must be signed in to change notification settings - Fork 413
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
Vectors are incredibly slow #321
Comments
I agree! vectors are 10 times slower then normal list of coords |
On the other side, internal Lua functions are pretty fast, so, maybe we need a custom version of lua, which has vectors by default, or something, because this way only MTA's source code benefits from Vectors. |
Actually, OOP in MTA is 10x slower than PP.. |
There is also a memory "problem" caused by infrequent garbage collection. See mantis 9840. It would be useful to document this online. Suggestions:
|
Wow that's heavy. This could be a hugh part of our performance issues. Our gamemode ist full written in oop and we used Vectors neary everywhere. |
I don't think it causes any performance issues, it would only affect memory usage. |
Memory issue was 'fixed' in 6f3fe6d (but Mantis was not updated) |
What do you mean under "in-place" operations? |
But even creating a Vector takes a lot of time for some reason. |
Tried in-place add, it nearly takes the same time to complete, so that didnt really help. operator+ can't be so slow since adding values up with simple dereferencing(so in-place) would be way faster. Edit: |
Summarisation of discussion in #mta.dev. Proposed next steps are:
|
Even if we implement vectors in Lua we won't be able to pass them trough events as the metatable will get lost in the process, so we don't fix #374 |
The coordinates will still be stored in the dictionary section Further work will need to be done to magically re-apply the metatable on the "other end", Potential solution for magically reapplying the metatable:
This same magically reapplying the metatable thing will need to be done when passing vectors between resources. Probably needs to be implemented as part of (Could actually be a generic setting like |
Does the "bad" OOP performance only apply to OOP functions or will the whole script performance suffer when i simply enable OOP in the meta while using only 1 OOP function in a big script? Because i need OOP to get the camera forward matrix and i dont want to break CPU performance even more. |
@Einheit-101 the performance issue is really only with Vectors and Matrices. Ultimately the issue is mostly due to garbage collection. If you do something simple like
If you did the same thing with three floats, each you'd not get a single object construction or destruction. |
Yeah, so I've looked around, and found this. // ltm.c:23
const char *const luaT_typenames[] = {
"nil", "boolean", "userdata", "number",
"vec", /* LUA-VEC */
"string", "table", "function", "userdata", "thread",
"proto", "upval"
}; (note the `/LUA-VEC/ comment) // lua.h:69
#define LUA_TNONE (-1)
#define LUA_TNIL 0
#define LUA_TBOOLEAN 1
#define LUA_TLIGHTUSERDATA 2
#define LUA_TNUMBER 3
#define LUA_TSTRING 4
#define LUA_TTABLE 5
#define LUA_TFUNCTION 6
#define LUA_TUSERDATA 7
#define LUA_TTHREAD 8
#define LUA_TVEC 9 /* LUA-VEC */ // lobject.h:19
/* tags for values visible from Lua */
#define LAST_TAG LUA_TVEC /* LUA_TTHREAD -- LUA-VEC */
#define NUM_TAGS (LAST_TAG+1)
/*
** Extra tags for non-values
*/
#define LUA_TPROTO (LAST_TAG+1)
#define LUA_TUPVAL (LAST_TAG+2)
#define LUA_TDEADKEY (LAST_TAG+3) |
But I am not excited about modifying our copy of Lua further. This isn't a no -- I'd just be a lot more excited if we had a proper Lua branch with our custom changes somewhere. |
so, I have successfully implemented
|
Describe the bug
So, using Vectors is a really good way to make your script more maintainable, but...
They are incredibly slow.
Here are some results:
Sub: 95 (Time it takes to do a simple i = i-i expression)
Function calls: 283 ms. (This is the time it takes to call a function.)
Expected behavior
I'd expect Vectors to be far more faster.
The main reason they are slow is they uselua_classmetamethod
, you may ask why:Because I made a little Vector class in Lua and ran a performance test, got nearly the same resultsthe difference was 300ms/1m runs(with integers, with floats it was a little bit less)Looks like comparation is pretty fast, maybe modification of the value is the slow part.
Additional context
Here's the test resource:
vectest.zip
(It's redundant a little and such, but really I just made it to ran these tests.)
The text was updated successfully, but these errors were encountered: