-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
compiler/wasm: memoize in function (not callsite) #3169
compiler/wasm: memoize in function (not callsite) #3169
Conversation
893bba2
to
d85df7f
Compare
😬 forgot about something: the args length check. |
1fee90a
to
8da631c
Compare
Also forgot that we can drop the memo around call_indirect, and thereby the elem_to_func mechanism. ✨ |
b1ed3f6
to
d0191f1
Compare
✔️ The |
As soon as a function is called twice, there should be a little bit to gain from having the memoization happen in the function body. Run on a big bundle, this results in the following change in opcode counts: Total opcodes: 184881 -> 183719 Opcode counts: local.get: 46920 -> 46760 - i32.const: 24152 -> 23706 - local.set: 14097 -> 14097 = call: 12547 -> 12061 - end: 10911 -> 11015 + br_if: 11062 -> 10826 - block: 8987 -> 9092 + So, the change isn't dramatic at all. But less is more, so I guess we could still do this. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
d0191f1
to
ac39e2f
Compare
c.appendInstr(instruction.GetLocal{Index: c.local(fn.Return)}) | ||
c.appendInstr(instruction.Call{Index: c.function(opaMemoizeInsert)}) | ||
} | ||
c.appendInstr(instr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 Currently, if this instruction is Return
, we could just ignore it. The last value on the stack is the function's return value, with our without that statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. It's nice how this cuts down the amount of code in the backend because we don't have to special case CallStmt vs CallDynamicStmt.
As soon as a function is called twice, there should be a little bit
to gain from having the memoization happen in the function body.
Run on a big bundle, this results in the following change in opcode
counts:
So, the change isn't dramatic at all. But less is more, so I guess
we could still do this.