Skip to content
This repository was archived by the owner on Sep 12, 2025. It is now read-only.

Commit 71f3dd5

Browse files
committed
New approach for ref types, use an auxillary thread stack
Vastly simpler and less magical than using a fixed size magical section of the active stack, and seems to be no slower. The only real downside is that it *seems* extremely extremely hacky (and to be fair, it is).
1 parent 60bfe1f commit 71f3dd5

File tree

10 files changed

+257
-432
lines changed

10 files changed

+257
-432
lines changed

CHANGELOG.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
## [0.14.0]
22
- Lots of performance improvements, including one major change: Lua handles no
3-
longer necessarily point into the registry, they now can instead point into a
4-
pre-allocated stack area. All together, you can expect (VERY rough estimate)
5-
somewhere on the order of 30%-60% CPU time reduction in the cost of bindings,
6-
depending on usage patterns.
3+
longer use the registry, they now instead are stored in an auxillary thread
4+
stack created solely for the purpose of holding ref values. This may seem
5+
extremely weird, but it is vastly faster than using the registry or raw tables
6+
for this purpose. The first attempt here was to use the same stack and to do
7+
a lot of complex bookkeeping to manage the references, and this DOES work, but
8+
it comes with a lot of complexity and downsides along with it. The second
9+
approach of using an auxillary thread turned out to be equally fast and with
10+
no real downsides over the previous approach. With all the performance
11+
improvements together, you can expect (VERY rough estimate) somewhere on the
12+
order of 30%-60% CPU time reduction in the cost of bindings, depending on
13+
usage patterns.
714
- Addition of some simple criterion.rs based benchmarking. This is the first
815
`rlua` release to focus on performance, but performance will hopefully remain
916
a focus going forward.
10-
- API incompatible change: Lua handles now must ONLY be used with the `Lua`
11-
instance from which they were derived. Before, this would work if both
12-
instances were from the same base state, but are now restricted to ONLY the
13-
matching `Lua` instance itself. This was previously only possible through
14-
unsafe code, `Lua::scope`, and things like the `rental` crate which allow self
15-
borrowing. For `Lua::scope` functions, you can use `Function::bind`, and for
16-
everything else you can use the `RegistryKey` API.
17-
- Another API incompatible change: `Lua` (and associated handle values) are no
18-
longer `UnwindSafe` / `RefUnwindSafe`. They should not have been marked as
19-
such before, because they are *extremely* internally mutable, so this can be
20-
considered a bugfix. All `rlua` types should actually be perfectly panic safe
21-
as far as *internal* invariants are concerned, but (afaict) they should not be
22-
marked as `UnwindSafe` due to internal mutability and thus potentially
23-
breaking *user* invariants.
17+
- API incompatible change: `Lua` is no longer `RefUnwindSafe` and associated
18+
handle values are no longer `UnwindSafe` or `RefUnwindSafe`. They should not
19+
have been marked as such before, because they are *extremely* internally
20+
mutable, so this can be considered a bugfix. All `rlua` types should actually
21+
be perfectly panic safe as far as *internal* invariants are concerned, but
22+
(afaict) they should not be marked as `RefUnwindSafe` due to internal
23+
mutability and thus potentially breaking *user* invariants.
2424
- Several Lua stack checking bugs have been fixed that could have lead to
2525
unsafety in release mode.
2626

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ considered a bug.
6464
Caveats to the panic / abort guarantee:
6565

6666
* `rlua` reserves the right to panic on API usage errors. Currently, the only
67-
time this will happen is when passed a handle type from a mismatched `Lua`
68-
instance, or when accessing outer level `Lua` instances and handles inside
69-
an inner callback.
67+
time this will happen is when passed a handle type from a `Lua` instance
68+
that does not share the same main state.
7069
* Currently, there are no memory or execution limits on scripts, so untrusted
7170
scripts can always at minimum infinite loop or allocate arbitrary amounts of
7271
memory.

0 commit comments

Comments
 (0)