Skip to content

Conversation

@ltratt
Copy link
Contributor

@ltratt ltratt commented May 2, 2025

Previously we added a YkLocation to the start of every Lua function, which meant that we created lots of (mostly) pointless traces.

This commit changes things so that only when we dynamically detect that a Lua function is recursive do we add a YkLocation to it. This largely prevents us tracing pointless functions.

This fix is done in constant time using a trick that took me a long while to realise: we only need to detect that we're in one level of recursion and we only need to do so the first time that happens. A single boolean suffices for this (previously I'd tried being much more precise, but (a) that required examining every call on the stack (b) it turns out not to be necessary): it's always accurate for the first recursive call, and only becomes inaccurate after that point (at which point we don't need it anyway).

TValue *k; /* constants used by the function */
Instruction *code; /* opcodes */
#ifdef USE_YK
/* Used to detect recursive function calls. When a function is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I were to nitpick (moi?), I'd format the comment like the others (with a star on each line).

@vext01
Copy link
Contributor

vext01 commented May 2, 2025

Very neat :) Just an nitpick comment.

@ltratt ltratt force-pushed the only_trace_recursive_functions branch from e251aa6 to 81241fd Compare May 2, 2025 15:21
@ltratt
Copy link
Contributor Author

ltratt commented May 2, 2025

Forced push a comment fix.

@ptersilie ptersilie added this pull request to the merge queue May 2, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 2, 2025
@vext01 vext01 added this pull request to the merge queue May 2, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 2, 2025
Previously we added a `YkLocation` to the start of every Lua function, which
meant that we created lots of (mostly) pointless traces.

This commit changes things so that only when we dynamically detect that
a Lua function is recursive do we add a `YkLocation` to it. This largely
prevents us tracing pointless functions.

This fix is done in constant time using a trick that took me a long
while to realise: we only need to detect that we're in one level of
recursion and we only need to do so the first time that happens. A
single boolean suffices for this (previously I'd tried being much more
precise, but (a) that required examining every call on the stack (b) it
turns out not to be necessary): it's always accurate for the first
recursive call, and only becomes inaccurate after that point (at which
point we don't need it anyway).
@ltratt ltratt force-pushed the only_trace_recursive_functions branch from 81241fd to a9bc71b Compare May 2, 2025 15:55
@ltratt
Copy link
Contributor Author

ltratt commented May 2, 2025

Force pushed an #ifdef fix.

@vext01 vext01 added this pull request to the merge queue May 2, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 2, 2025
@jacob-hughes jacob-hughes added this pull request to the merge queue May 2, 2025
Merged via the queue into ykjit:main with commit f2ce363 May 2, 2025
2 checks passed
@ltratt ltratt deleted the only_trace_recursive_functions branch May 30, 2025 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants