Skip to content
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

Add Lua bindings #299

Merged
merged 95 commits into from
May 30, 2022
Merged

Add Lua bindings #299

merged 95 commits into from
May 30, 2022

Conversation

wtfsck
Copy link
Member

@wtfsck wtfsck commented May 22, 2022

TODO

I tried mlua first but it had too much overhead. Switched to using the C API and I got much better speed. Lua 5.1 decoder iter: 75MB/s, Lua 5.4 90MB/s (Python with pyo3: 50MB/s)

Lua 5.1 (old mlua crate vs using the C API):

                ( old code ->  new code)
1.  6.2x faster ( 9.87MB/s -> 61.00MB/s): for loop with fixed count + decode_out()
2.  6.8x faster ( 5.71MB/s -> 38.84MB/s): can_decode() + decode_out()
3.  7.1x faster (10.41MB/s -> 74.30MB/s): iter_out()
4. 15.2x faster ( 1.16MB/s -> 17.62MB/s): iter() (allocs a new Instruction every iter)

wtfsck added 30 commits April 30, 2022 18:20
- Redirect `which` output to `/dev/null`
- Add double quotes
- Use `"$@"` to pass all args to `build`/`install`
It's slow, though... Too slow. Slower than the fastest snail, but
probably faster than the slowest snail.

- `mlua` could have a lot of overhead
- Lua wrapper tables could be bad too
- Lua FFI is slow?
- Or a combination

I put this at the end because maybe you won't see it.

I got 6.6MB/s. Compare that to Rust 260MB/s, C# 130MB/s, Python 50MB/s.
This is consistent with the manually written docs and seems like other
Lua code (eg. the examples from
https://github.com/sumneko/lua-language-server/wiki/EmmyLua-Annotations)
also don't use spaces.
- Name should really be `luna` but it was taken
- Lua 5.1 for now. Will add 5.2, 5.3, 5.4 later
- A quick test shows that using the C API is much faster than `mlua`
  (and probably `rlua` since `mlua` is a fork of `rlua`)
- Get usize/isize args
- `lua_module!()` and `lua_method!()` macros
This is much faster than the old code.

Lua 5.1:

               ( old code ->  new code)
1.  6.2x faster ( 9.87MB/s -> 61.00MB/s): for loop with fixed count + decode_out()
2.  6.8x faster ( 5.71MB/s -> 38.84MB/s): can_decode() + decode_out()
3.  7.1x faster (10.41MB/s -> 74.30MB/s): iter_out()
4. 15.2x faster ( 1.16MB/s -> 17.62MB/s): iter() (allocs a new Instruction every iter)
`get_user_data()` used to return `&mut` but many callers only need an
immutable reference.
- Add a bunch of `Instruction` methods, examples not updated from Python
  code
- Enable all iced-x86 features
- Make sure the metatable is initialized even if the module hasn't been
  loaded yet. Eg. `Decoder` can create an `Instruction` even when the
  `Instruction` module hasn't been loaded yet.
- Update method macros to create a `&Lua<'lua>` instead of `Lua<'lua>`
  so it's always the same type.
- Add a more `Lua::push_{u32,f32,etc}()` methods
- Rename `Instruction::new()` -> `Instruction::push_new()` since it
  pushes a value onto the Lua stack.
wtfsck added 28 commits May 22, 2022 11:09
- Remove setter docs. Will be copied by the doc gen code
- Fix wrong types in docs, eg. `str` -> `string`
- Add missing `@param`
- `@returns` should be `@return`
- Use `an`
Similar to the Python pyi generator, this reads the Rust comments and
spits out EmmyLua files that will be read by the Lua language server.
- 5.1.3: `lua_setlevel()`
- 5.2.2: `lua_ident`
- 5.4.3: `lua_closeslot()`
@wtfsck wtfsck merged commit 2a037ab into master May 30, 2022
@wtfsck wtfsck deleted the lua branch May 30, 2022 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant