-
Notifications
You must be signed in to change notification settings - Fork 18
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
Idea: Optimization of "struct" and "fields" objects #52
Comments
On 4/6/14 11:19 PM, romix wrote:
Well, if the values are not cdata types then that wouldn't work.
I've experimented with this kind of thing. So you do save on space. What's more, there's also no guarantee that the members are going to be The thing is that Lua's tables are fast because the don't re-hash the I've had cases where using LuaJIT's tables are faster than C structs. It
LuaJIT has a TDUP instruction. What the compiler does is store the
Then the It's not like this stuff is actually slow, right?
It's been suggested before on the mailing list to make LuaJIT more If your language has mutable strings, then you'd need to replace the So it's actually a fairly non-trivial job to make the LuaJIT VM generic
Then An interesting idea would definitely be to integrate the FFI more into
You'd then get the This gets hairy though, because what does Right now the fact that you need to pass strings to
Sure, all good ideas. For now though, I feel that Shine is squeezing |
Absolutely! It was not proposed as a high-priority feature for a near future. And of course I'm interested in understanding how to use LuaJIT as a target for other languages. In particular for things that have a semantic diverging from Lua's semantics. And for things that may be CPU-intensive, i.e. where certain optimizations (or lack of them) start playing an important role... But this is of course out of scope for Shine, at least in its current development stage. Concentrating on optimizations makes sense (if at all), once the language has stabilized and performance becomes an issue...
It was actually me who asked for it ;-) I still think that LuaJIT could be a wonderful target for many languages if it would be a bit more friendly... I haven't given up on this idea yet. But this is another story ... |
On 4/7/14 10:52 AM, romix wrote:
If you really wanted to diverge, then you actually could get pretty Then I'd move all my VM "instructions" into a C library and use only So With this scheme you're still using the stack slots and GC roots, but Then the only problem you have is for non-scalar types: arrays, hashes Coroutines could get tricky, but it's still doable. One of the main reasons I didn't go this route is because I wanted to be |
This is just an idea.
"struct" and "fields" allow for defining types that have a fixed structure. May be this information can be used for more efficient access to these objects both in terms of memory usage and performance?
The following optimizations could be potentially possible:
Or at least to an Lua-table which has only array elements. Each field name gets mapped to an array-index. obj.fieldX becomes obj[idX]. This could be more memory efficient than hash-table based storage of those fields.
(1) is also somewhat similar to Python's named tuples: https://docs.python.org/2/library/collections.html#collections.namedtuple
They may use less memory and be accessed more efficiently.
May be LuaJIT/compiler may make use of the fact that the structure of objects does not change during run-time? This information could be used e.g. for copy propagation and some other optimizations... I'm not sure though that LuaJIT is able on its own to understand that structure of objects(i.e. tables) is fixed (this needs to be tested yet). Eventually, it may require some help, e.g. some hints ( a-la PyPy JIT hints).
Note: Overall, it would be interesting to understand if a compiler or runtime of Shine may somehow provide hints to LuaJIT to enable better optimizations. I understand that currently LuaJIT does not provide support for this. But if it would, what could be done? This kind of input could interesting for Mile Pall to convince him that supporting some sort of hints could be very valuable.
As I said, these are just some ideas. I'm not sure how feasible they are and if something like this is possible at all.
What do you think?
The text was updated successfully, but these errors were encountered: