-
Notifications
You must be signed in to change notification settings - Fork 558
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
Implement remaining Lua runtime libraries #1075
Open
kevin-montrose
wants to merge
26
commits into
main
Choose a base branch
from
luaRuntimeLibraries
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains 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
… and we can configure it reasonably; implements a number of workarounds to accomplish this, as the 5.1 <-> 5.4 Lua version difference also had some library changes
…re pretty sloppy, so ran tests against Redis first to verify matching behavior
…a superset of what Redis wants; technically we allow more than Redis does, but I think that's a reasonable tradeoff for implementation complexity
…exception tests on Linux until that refactor happens
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.
Changes:
LuaAllowedFunctions
)cjson.encode
andcjson.decode
bit.*
functionsmath.*
functionscmsgpack.pack
andcmsgpack.unpack
struct.pack
,struct.unpack
, andstruct.size
TODOs:
math.*
functionsList<byte>
orbyte[]
instances and instead useScratchBufferManager
While large, this is basically rote as it's just filling it a bunch of missing functions.
Note that
getfenv
andsetfenv
remain unimplemented, as they're Lua 5.1-isms that would be very difficult to implement and are rarely used. Users can adapt their scripts to useload
instead as a workaround.LuaAllowedFunctions
This controls the set of global functions available to a Lua script, including functions grouped under
redis
.This is mostly a defense in depth thing for when Garnet is hosted as a service, allowing problematic functions to be disabled without code changes.
cjson
Serialization is bespoke because of the need to handle data passed on the Lua stack.
Deserialization uses .NET's built-in
JsonNode
.cmsgpack
Rather than pull in a dependency, I implemented both serialization and deserialization.
The format isn't too complicated and serialization would be bespoke for the same reasons as
cjson.encode
, so it seemed like a reasonable decisions.Linux test skips
Some of these tests are finally reproducing the
longjmp
issue the .NET folks warned about, and failing pretty reliably. For these tests, I'm skipping the exception parts on not-Window with a TODO for the next phase.Benchmarks
main
is as of225b2ae13c37e9583b752e068a4058b603f69c0a
luaRuntimeLibraries
is as of225b2ae13c37e9583b752e068a4058b603f69c0a
Just reporting
LuaRunnerOperations
(and just Native memory management) as that's where the impact is expected to be largest.TL;DR - Construction costs are up, as expected, since the loader block is much larger now. Biggest relative hit is in
ConstructSmall
where the loader block dominates, and is ~34%. Compilation is somewhat improved (~20%), as more of the loader runs at construction time.I can picture a way to speed this up (basically, keeping some
LuaStateWrapper
s pre-initialized and having sessions obtain them on demand), but I'm not sure it's worth the complexity.main
luaRuntimeLibraries
Related Issues