Skip checkDebug()'s Python round-trip entirely in fast-continue mode - #52
Merged
Conversation
Found via a real BelfrySCAD bug report: debugging a NURBS-surface script and immediately clicking Continue took ~2x longer than a plain render, even with per-function fast-continue (existing feature) already engaged. Measured root cause: 462,094 checkDebug() calls still crossed into Python even with fast-continue fully applied -- module/ geometry evaluation never compiles (a deliberate, separate system, see docs elsewhere), so every statement there still called into Python just to be told "continue". Disabling fast-continue entirely made this 5.99 million calls -- confirming those calls WERE genuinely being helped, just not eliminated. Extends the same mechanism to checkDebug() itself, not just VM eligibility: setFastContinueBreakpoints gains a second `hookSkippable` parameter (true only for a plain "Continue" with no step pending -- step_over/step_out still need every statement inspected for their own step_hit logic, so they keep hookSkippable=false even though they also pass a real breakpoints set). checkDebug() then skips the whole Python call (and the childStatementPositions/getFrame setup before it) for any line with no breakpoint, in that mode. Since debug_evaluate() runs as one single blocking call with the GIL released for its duration, there's no live Python-callable Evaluator handle DebugSession.pause()/set_breakpoints() (main thread) could otherwise interrupt directly. Adds FastContinueSignal: a small, lock-free, GIL-free shared flag a caller creates once per debug session and calls .request() on to guarantee the very next checkDebug() call isn't skipped, regardless of whether it hits a breakpoint -- checkDebug() test-and-clears it atomically. breakpoint() (forced=true) always bypasses the skip, unaffected. New tests in test_debug_hooks.cpp cover: skip with no matching breakpoint, still-fires at a matching one, unaffected when not hook-skippable (step_over/out), the interrupt flag forcing a call through, and breakpoint()'s own bypass. Full 1297-test suite passes; verified end-to-end via the actual Python binding (20,007 -> 1 hook call for a representative script). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
checkDebug()calls still crossed into Python even with fast-continue fully applied, because module/geometry evaluation never compiles (a separate, always-interpreted system) — every statement there still called into Python just to be told "continue". Disabling fast-continue entirely ballooned this to 5.99 million calls, confirming the existing feature was helping, just not eliminating the cost.checkDebug()itself, not just VM eligibility:setFastContinueBreakpointsgains a secondhookSkippableparameter — true only for a plain "Continue" with no step pending.step_over/step_outkeephookSkippable=falseeven though they also pass a real breakpoints set, since they still need every statement inspected for their ownstep_hitlogic.FastContinueSignal: a small, lock-free, GIL-free shared flag, sincedebug_evaluate()runs as one single blocking call with the GIL released for its duration — there's no live Python-callableEvaluatorhandlepause()/set_breakpoints()could otherwise interrupt directly. A caller creates one per debug session and calls.request()to guarantee the very nextcheckDebug()call isn't skipped.breakpoint()(forced=true) always bypasses the skip, unaffected.Test plan
test_debug_hooks.cpp: skip with no matching breakpoint, still-fires at a matching one, unaffected when not hook-skippable (step_over/out), interrupt flag forcing a call through,breakpoint()'s own bypass.test_python_bindings.py: 13/13 passing, unmodified (new params have defaults).hook_skippable=Trueand no breakpoints; unaffected (20,007) withhook_skippable=False.🤖 Generated with Claude Code