Skip to content

Optimize thread resume/yield #593

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

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
6cfa226
mlua continuation yield
Jun 4, 2025
e01e45f
add missing xmove
Jun 4, 2025
bd6b65b
remove comment
Jun 4, 2025
c6f1ff2
add a f32 to test stack
Jun 4, 2025
875d6e8
cleanup
Jun 4, 2025
2a67b26
deal with warnings
Jun 4, 2025
d23f058
update warning
Jun 4, 2025
62330e7
allow yield on non-luau as well
Jun 4, 2025
1c7743c
fix
Jun 5, 2025
85416fd
Document continuations a bit more
Jun 5, 2025
b3a54ac
reuse same preallocatedfailure in both callback_error_ext and callbac…
Jun 5, 2025
085c62a
handle mainthread edgecase
Jun 5, 2025
198b857
fix import
Jun 5, 2025
2cd34db
support empty yield args
Jun 5, 2025
23b7705
add more tests for cont
Jun 5, 2025
dd3ea05
ensure check_stack of state
Jun 5, 2025
52176a8
rename to luau continuation status
Jun 6, 2025
10d2df4
add support for continuations outside luau
Jun 6, 2025
8400386
fix
Jun 6, 2025
5d86852
fix
Jun 6, 2025
9e77e5c
fix
Jun 6, 2025
eb63755
fix yieldable continuation on non-luau
Jun 6, 2025
9def001
fix luau compiler bug
Jun 6, 2025
e985f83
add note on why pop
Jun 6, 2025
3dcb131
fix docs which incorrectly state only luau supports yieldable continu…
Jun 6, 2025
3a079fe
make the api more ergonomic
Jun 6, 2025
3c005d7
rename set_yield_args to yield_with
Jun 6, 2025
c7ddbe6
partially revert due to compiler error
Jun 6, 2025
b44075f
fix
Jun 6, 2025
a2e8694
fix
Jun 6, 2025
4a37dc5
ensure wrappedfailure is returned to pool
Jun 6, 2025
a5c1ea1
fix wrap error case
Jun 6, 2025
541331c
begin adding auxthread code
Jun 7, 2025
cfc942d
fix more places
Jun 7, 2025
4174bdd
remove useless print calls
Jun 7, 2025
42c8d16
ensure compare_refs use right indices
Jun 7, 2025
a43b0db
fix indices again
Jun 7, 2025
dcd87c3
Update util.rs
cheesycod Jun 7, 2025
5d0a2d9
fix
Jun 8, 2025
3fb7abc
split out large thread create tests
Jun 8, 2025
4b8140b
add retest of continuation/yield across continuation
Jun 8, 2025
c68b990
fix partialeq
Jun 8, 2025
cbca60c
debug
Jun 8, 2025
c385453
fix index in create_thread
Jun 8, 2025
aee199f
remove
Jun 8, 2025
2e68555
fix thread
Jun 8, 2025
cd84332
optimize thread state args
Jun 10, 2025
707d551
Merge branch 'mlua-rs:main' into mlua-listofaux
cheesycod Jun 10, 2025
a46eae2
.
Jun 10, 2025
1f5f225
Merge branch 'mlua-rs:main' into threadopt
cheesycod Jun 10, 2025
223d49f
clean up
Jun 11, 2025
9bb1794
very slight perf optimization to status_inner
Jun 11, 2025
c4fadfd
expose try_cache
Jun 11, 2025
7060753
fix tests
Jun 12, 2025
09b835e
Merge branch 'mlua-listofaux' into main
cheesycod Jun 12, 2025
d7e89cc
fix
Jun 12, 2025
1d19bee
Merge branch 'threadopt' into main
cheesycod Jun 12, 2025
52b410c
Merge pull request #2 from cheesycod/main
cheesycod Jun 12, 2025
bb85dfa
fix to use push_at vs push
Jun 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mlua-sys/src/lua52/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ pub unsafe fn lua_yield(L: *mut lua_State, n: c_int) -> c_int {
lua_yieldk(L, n, 0, None)
}

#[inline(always)]
pub unsafe fn lua_yieldc(L: *mut lua_State, n: c_int, k: lua_CFunction) -> c_int {
lua_yieldk(L, n, 0, Some(k))
}

//
// Garbage-collection function and options
//
Expand Down
5 changes: 5 additions & 0 deletions mlua-sys/src/lua53/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ pub unsafe fn lua_yield(L: *mut lua_State, n: c_int) -> c_int {
lua_yieldk(L, n, 0, None)
}

#[inline(always)]
pub unsafe fn lua_yieldc(L: *mut lua_State, n: c_int, k: lua_KFunction) -> c_int {
lua_yieldk(L, n, 0, Some(k))
}

//
// Garbage-collection function and options
//
Expand Down
5 changes: 5 additions & 0 deletions mlua-sys/src/lua54/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ pub unsafe fn lua_yield(L: *mut lua_State, n: c_int) -> c_int {
lua_yieldk(L, n, 0, None)
}

#[inline(always)]
pub unsafe fn lua_yieldc(L: *mut lua_State, n: c_int, k: lua_KFunction) -> c_int {
lua_yieldk(L, n, 0, Some(k))
}

//
// Warning-related functions
//
Expand Down
5 changes: 5 additions & 0 deletions mlua-sys/src/luau/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ pub unsafe fn lua_pushcclosure(L: *mut lua_State, f: lua_CFunction, nup: c_int)
lua_pushcclosurek(L, f, ptr::null(), nup, None)
}

#[inline(always)]
pub unsafe fn lua_pushcclosurec(L: *mut lua_State, f: lua_CFunction, cont: lua_Continuation, nup: c_int) {
lua_pushcclosurek(L, f, ptr::null(), nup, Some(cont))
}

#[inline(always)]
pub unsafe fn lua_pushcclosured(L: *mut lua_State, f: lua_CFunction, debugname: *const c_char, nup: c_int) {
lua_pushcclosurek(L, f, debugname, nup, None)
Expand Down
2 changes: 1 addition & 1 deletion src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Buffer {
unsafe fn as_raw_parts(&self) -> (*mut u8, usize) {
let lua = self.0.lua.lock();
let mut size = 0usize;
let buf = ffi::lua_tobuffer(lua.ref_thread(), self.0.index, &mut size);
let buf = ffi::lua_tobuffer(lua.ref_thread(self.0.aux_thread), self.0.index, &mut size);
mlua_assert!(!buf.is_null(), "invalid Luau buffer");
(buf as *mut u8, size)
}
Expand Down
2 changes: 1 addition & 1 deletion src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ impl Chunk<'_> {
/// Fetches compiled bytecode of this chunk from the cache.
///
/// If not found, compiles the source code and stores it on the cache.
pub(crate) fn try_cache(mut self) -> Self {
pub fn try_cache(mut self) -> Self {
struct ChunksCache(HashMap<Vec<u8>, Vec<u8>>);

// Try to fetch compiled chunk from cache
Expand Down
Loading