Repository navigation
Inherit host hooks when creating Lua threads and coroutines - #355
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Installing a host count hook on a parent left loops in its child coroutines unmonitored. Copy host hook settings when creating a thread/coroutine through either C# or Lua, so a child's instructions invoke the same callback with that child's execution context.
The inheritance contract follows native Lua's creation-time snapshot:
debug.sethookseparately: its callback stays thread-local. Children inherit observable mask/count metadata without dispatching the parent's Lua callback.Native C probes compiled from official Lua 5.2.4 and 5.4.9 confirmed callback inheritance, fresh counters, independent replacement/removal, and Lua callback/metadata behavior through grandchildren. Relevant source: 5.2 lua_newthread, 5.2 hookf, 5.4 lua_newthread, 5.4 hookf.
Document the shared callback/context.State contract and sandbox limits in both READMEs and API/source comments. A hook must be installed before children are created or explicitly set on existing children. Exposed
debug.sethookcan still remove it;LuaRuntimeExceptioncan still be caught bypcall/protectedcoroutine.resume. This is inherited instrumentation, not an uncatchable VM-wide execution budget.Validation:
BenchmarkDotNet ShortRun, .NET 8.0.31 CoreCLR, main a2c3934 versus this change:
These short measurements show no material regression for equal monitoring; they do not establish a general speedup. Newly inherited monitoring necessarily adds the existing hook-dispatch cost to previously unmonitored children (about 3x for this count=4 loop). The per-instruction VM dispatch is unchanged.
Refs #338; lightweight delegate/budget APIs remain deferred.