Uh oh!
There was an error while loading. Please reload this page.
perf: back say and Http.Status.set with EffectFn1 foreigns - #8
Merged
Conversation
The curried String -> Effect Unit FFI shape compiles every call into
two Lua calls plus a fresh effect-thunk closure. Declaring the foreigns
as EffectFn1 (sayImpl, setImpl) behind thin public wrappers keeps the
API unchanged while letting the compiler collapse saturated call sites
into one direct call: M.say("x")() becomes sayImpl("x"). Demonstrated
by a differential link of a probe app against this branch vs main.
Refs purescript-lua/purescript-lua#186.
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 freeto 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.
Problem
say :: String -> Effect UnitandLua.Ngx.Http.Status.set :: Status -> Effect Unitwere curried effect foreigns, so every call paid two Lua calls plus a freshly allocated effect thunk. With the compiler's uncurried lift in place (purescript-lua/purescript-lua#198), anEffectFn1shape compiles to a single direct call instead. These are exactly the Lua-specific foreigns the #186 audit scoped for conversion (ngx has no upstream to stay API-compatible with, and the public API does not change anyway).Change
The foreigns become
sayImpl/setImpl :: EffectFn1 …with thin public wrappers (say = runEffectFn1 sayImpl), and the.luaentries become 1-ary functions performing the effect directly.get :: Effect Statusstays as is: a thunk is already a single call, and there is noEffectFn0. Status constants untouched.Verification
scripts/buildgreen. Differential link of a probe app (say "hello" *> say "world" *> set ok) againstmainvs this branch: every call site collapses fromLua_Ngx_say("hello")()(two calls and a closure per invocation) toLua_Ngx_sayImpl("hello"), one direct call with the effect thunk fused away by magic-do. Both linked outputs were executed under Lua 5.1 with anngxstub and produce identical behaviour (same say output, same status assignment). No OpenResty runtime smoke: the change surface is the calling convention only.Suggested release: minor (v0.3.0, since the module surface gains the
*Implexports) plus a package-set bump.Refs purescript-lua/purescript-lua#186.