mirror of
https://github.com/allankoechke/ADN-3dsMax-Explode-Geometry.git
synced 2026-11-30 09:22:10 +00:00
[PR #2] [CLOSED] feat: perf: test on performance with logging #5
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/allankoechke/ADN-3dsMax-Explode-Geometry/pull/2
Author: @allankoechke
Created: 6/19/2026
Status: ❌ Closed
Base:
master← Head:1-logging-perf-eval📝 Commits (6)
8d4f1c8feat: begin implementation for #14ecf22bfeat: create perf/ benchmarking folder with 6 variant scripts and runnereffb9d9feat: migrate Python/explode_geometry.py from print() to logging module6d77157feat: sync Bundle2/Contents/python/explode_geometry.py with logging migration6b56883feat: add perf/RESULTS.md template for benchmark recording79f2b04feat: perfomance benchmarks📊 Changes
11 files changed (+741 additions, -68 deletions)
View changed files
📝
.gitignore(+2 -0)📝
Bundle2/Contents/python/explode_geometry.py(+51 -34)📝
Python/explode_geometry.py(+51 -34)➕
perf/RESULTS.md(+66 -0)➕
perf/explode_geometry_devnull.py(+87 -0)➕
perf/explode_geometry_errors_only.py(+61 -0)➕
perf/explode_geometry_logger_all.py(+97 -0)➕
perf/explode_geometry_logger_info.py(+97 -0)➕
perf/explode_geometry_noprint.py(+60 -0)➕
perf/explode_geometry_print.py(+78 -0)➕
perf/runner.py(+91 -0)📄 Description
Closes #1
Logging Performance Evaluation Implementation Plan
Overview
Replace the 30 synchronous
print()calls in the Explode Geometry plugin with Python'sloggingmodule (level=WARNING in production), and run real-world benchmarks inside 3ds Max across all evaluated approaches to validate the expected ~190x-1000x speedup on per-face-count-scaling workloads.Current State Analysis
Key Discoveries:
Python/explode_geometry.py:156-283— 30print()calls across 4 functions; all use.format()(eager), meaning string construction happens even if output is discardedBundle2/Contents/python/explode_geometry.py— identical file; must receive identical changesPython/explode_geometry_classic.py:176,273— legacy MaxPlus/Python 2 file with only 2 prints; out of scope (Python 2 syntax, max 2021 only)convert_to_triangle_faces():227-228formats 11 arguments including 9 floats — this single call scales as O(faces) and is the dominant cost driversys.stdoutto the MaxScript Listener (Scintilla GUI widget), making eachprint()synchronous and blocking on the main thread with GUI repaint overheadlogger.debug("msg %s", arg)with level=WARNING costs ~14 ns/call (level-check short-circuit), versus ~2,660 ns+ perprint()to Listener — ~190x improvement floor, 1000x+ with GUI overhead factored in%formatting is essential:logger.debug(f"...")orlogger.debug("...".format(...))still evaluates the string before the level check, negating the benefitDesired End State
After this branch is complete:
perf/folder exists with 6 variant scripts and arunner.pythat can be executed inside 3ds Max to produce a timing tablePython/explode_geometry.pyandBundle2/Contents/python/explode_geometry.pyuse theloggingmodule with level=WARNING in production, lazy%formatting, and dual handlers (stdout for INFO and below, stderr for WARNING+)perf/RESULTS.md) showing measured wall-clock times for each variant on a standardized test meshVerification: Running
runner.pyinside 3ds Max produces a complete timing table with no errors. The logging variant scripts do not emit any output to the MaxScript Listener during normal (non-error) operation.What We're NOT Doing
Python/explode_geometry_classic.py— legacy MaxPlus/Python 2 file, not used in Max 2022+Implementation Approach
Selected approach from research: Python
loggingmodule with:logger = logging.getLogger("ExplodeGeometry")sys.stdoutfor DEBUG/INFO (white Listener text),sys.stderrfor WARNING+ (red Listener text)logging.WARNING— all debug/info calls cost ~14 ns (level-check only).format()calls converted to lazy%style on debug/info log linesBenchmarking first (TASK 1) establishes the baseline before modifying production code, so results reflect the actual before/after difference.
IMPORTANT: Checkboxes are for implementation steps only. Steps requiring manual human verification (browser testing, manual QA, visual inspection, staging verification, human review) MUST NOT be checkboxes — place them in the numbered "Manual Testing Steps" section at the bottom of the plan instead.
TASK 1: Create perf/ Benchmarking Folder [HIGH PRIORITY]
Status: DONE
Milestone:
perf/folder exists with all 6 variant scripts and a workingrunner.pythat can be executed inside 3ds Max to produce a timing comparison tableperf/directory at the repository rootperf/explode_geometry_print.py— copy of the currentPython/explode_geometry.pywith all 30print()calls unchanged; this is the "before" baselineperf/explode_geometry_errors_only.py— remove all 29 debug/info prints, retain only the single error print at L167 (print("[ExplodeGeometry] ERROR: {}".format(msg))); this is the practical production minimumperf/explode_geometry_devnull.py— addimport osand redirectsys.stdout = open(os.devnull, "w")at module level before any print calls; all 30 prints remain unchangedperf/explode_geometry_logger_all.py— fullloggingmodule setup (dual handlers as per the implementation sketch),logger.setLevel(logging.DEBUG)so all 30 messages are emitted; convert all.format()to lazy%perf/explode_geometry_logger_info.py— same as logger_all butlogger.setLevel(logging.INFO); the per-face debug calls (the O(faces) hotspot) are filtered out, config/lifecycle messages still emittedperf/explode_geometry_noprint.py— remove all 30 print statements entirely; no logging setup; this is the theoretical performance floorperf/runner.pywith the following structure:importlib.import_moduleorexec(open(...).read())since they share function names)rt.resetMaxFile(noPrompt=True), (2) create a standard test cone (rt.Cone(radius1=50, radius2=0, height=100, heightsegs=10, capsegs=5, sides=32)), (3) select it withrt.select(cone), (4) calltime.perf_counter()before and after the variant'sconvert_to_triangle_faces()function directly (bypassing GUI), (5) clear scene, recreate cone, (6) repeat forconvert_to_mnmesh_faces()| variant | explode type | time (s) |import timeforperf_counter()Validation: Running
runner.pyinside the 3ds Max Python listener (e.g., via pasting into the listener) produces a complete table with 12 data rows and no import errors.Requirements from spec:
time.perf_counter()) on a standardized test mesh inside 3ds MaxFiles to Create:
perf/runner.py— orchestrator that imports each variant and runs timing measurementsperf/explode_geometry_print.py— baseline: all 30 prints as-isperf/explode_geometry_errors_only.py— 29 prints removed, 1 error print retainedperf/explode_geometry_devnull.py— stdout redirected to os.devnull, prints unchangedperf/explode_geometry_logger_all.py— logging module, level=DEBUG, all messages emittedperf/explode_geometry_logger_info.py— logging module, level=INFO, per-face debug filteredperf/explode_geometry_noprint.py— zero prints, no loggingTASK 2: Migrate Python/explode_geometry.py to logging module [HIGH PRIORITY]
Status: DONE
Milestone: All 30
print()calls replaced withlogger.*()calls using lazy%formatting; logger setup at module level with dual handlers; production level set to WARNINGimport loggingandimport systo the imports section (after the existingimport randomat L12)rt = pymxs.runtime(around L13), using anif not logger.handlers:guard to prevent duplicate handlers on script reload:logger = logging.getLogger("ExplodeGeometry")addFilter(lambda r: r.levelno < logging.WARNING)logger.setLevel(logging.WARNING)for productiondo_explode()) withlogger.debug()calls using%slazy formattinglogger.warning("ERROR: %s", msg)so it routes to stderr (red Listener text)Processing N object(s)) withlogger.debug("[TriMesh] Processing %d object(s)", len(transformation_set))Object i/N: name) withlogger.debug("[TriMesh] Object %d/%d: %s", i, len(transformation_set), n.name)Deleting original) withlogger.debug("[TriMesh] Deleting original %s", n.name)[MNMesh] Processing) withlogger.debug("[MNMesh] Processing %d object(s)", len(transformation_set))[MNMesh] Object i/N) withlogger.debug("[MNMesh] Object %d/%d: %s", i, len(transformation_set), node.name)[MNMesh] Deleting) withlogger.debug("[MNMesh] Deleting original %s", node.name)Done. Redrawing views.) withlogger.info("Done. Redrawing views.")Converting to mesh) withlogger.debug("[TriMesh] Converting %s to mesh...", node.name)has N face(s)) withlogger.debug("[TriMesh] %s has %d face(s) to explode", node.name, num_faces)logger.debug("[TriMesh] Face %d/%d: verts=(%.2f,%.2f,%.2f) (%.2f,%.2f,%.2f) (%.2f,%.2f,%.2f)", face_idx, num_faces, v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, v3.x, v3.y, v3.z)— lazy%means vertex coords are NOT read/formatted when level=WARNINGCreated piece) withlogger.debug("[TriMesh] Created piece %s for face %d", new_node.name, face_idx)Finished exploding) withlogger.debug("[TriMesh] Finished exploding %s", node.name)[Poly] Converting) withlogger.debug("[Poly] Converting %s to poly...", node.name)[Poly] has N face(s)) withlogger.debug("[Poly] %s has %d face(s) to explode", node.name, num_faces)Detaching face) withlogger.debug("[Poly] Detaching face %d/%d", face_idx, num_faces)WARNING: Could not find detached node) withlogger.warning("[Poly] WARNING: Could not find detached node for face %d", face_idx)— routes to stderr (red text)Created piece) withlogger.debug("[Poly] Created piece %s for face %d", new_node.name, face_idx)Finished exploding) withlogger.debug("[Poly] Finished exploding %s", node.name)applySettingssummary) withlogger.debug("applySettings on %s: shell=%s (amt=%s) editMesh=%s collapse=%s centerPivot=%s", n.name, addShell, shell_amount, addEditMesh, collapseNode, centerPivot)Adding Shell modifier) withlogger.debug("Adding Shell modifier (outerAmount=%s)", shell_amount)Adding Edit Mesh modifier) withlogger.debug("Adding Edit Mesh modifier")Collapsing modifier stack) withlogger.debug("Collapsing modifier stack")Centering pivot) withlogger.debug("Centering pivot")Validation: After editing,
grep -c "print(" Python/explode_geometry.pyreturns 0. The file parses cleanly:python -c "import ast; ast.parse(open('Python/explode_geometry.py').read()); print('OK')"returns OK.Requirements from spec:
%formatting (not f-strings or.format()) on all logger callslogger.warning()to route to stderr (red Listener text)if not logger.handlers:guard) to survive script reload in 3ds Maxlogging.WARNINGso normal operation emits nothing to the ListenerFiles to Modify:
Python/explode_geometry.py— add logger setup, replace all 30 print() callsTASK 3: Sync Bundle2/Contents/python/explode_geometry.py [MEDIUM PRIORITY]
Status: DONE
Milestone:
Bundle2/Contents/python/explode_geometry.pyis identical to the updatedPython/explode_geometry.pyBundle2/Contents/python/explode_geometry.py(the file is currently identical toPython/explode_geometry.py, so the same set of edits applies line-for-line)diff Python/explode_geometry.py Bundle2/Contents/python/explode_geometry.pyshould produce no outputValidation:
diff Python/explode_geometry.py Bundle2/Contents/python/explode_geometry.pyexits 0 with no output.Requirements from spec:
Files to Modify:
Bundle2/Contents/python/explode_geometry.py— identical changes as TASK 2TASK 4: Run Benchmarks and Record Results [MEDIUM PRIORITY]
Status: DONE
Milestone: Real benchmark results from inside 3ds Max are documented, confirming the logging module approach shows the expected performance improvement
perf/runner.pyin 3ds Max (e.g., drag-drop into viewport or paste into the Python listener:exec(open(r"perf/runner.py").read()))perf/RESULTS.mdwith the captured table, the test mesh parameters (cone: radius1=50, radius2=0, height=100, heightsegs=10, capsegs=5, sides=32), and the 3ds Max version usedexplode_geometry_logger_infoandexplode_geometry_noprintshow meaningfully faster times thanexplode_geometry_printfor both TriMesh and MNMesh pathsValidation:
perf/RESULTS.mdexists and contains a 12-row table. The logger_info and noprint variants show measurably faster times than the print baseline for TriMesh on the standard test mesh.Requirements from spec:
Files to Create:
perf/RESULTS.md— captured timing table with test environment detailsTesting Strategy
Unit Tests:
python -c "import ast; ast.parse(open('Python/explode_geometry.py').read()); print('OK')"— syntax validationgrep -c "print(" Python/explode_geometry.pymust return 0grep -c "print(" Bundle2/Contents/python/explode_geometry.pymust return 0diff Python/explode_geometry.py Bundle2/Contents/python/explode_geometry.pymust return no diffIntegration Tests:
ast.parseon each)runner.pyexecutes inside 3ds Max without exceptions and prints a complete 12-row tableManual Testing Steps:
Python/explode_geometry.py— verify the MaxScript Listener shows NO output during a successful explode (production level=WARNING filters all debug/info)logger.setLevel(logging.DEBUG)in the script, re-run — verify all the familiar debug messages appear in white text in the Listener (confirming the handler wiring is correct)perf/runner.pyinside 3ds Max and verify the table is printed with 12 rows covering all 6 variants x 2 mesh types, with no exceptionsPerformance Considerations
%formatting on everylogger.debug()call — eager f-strings or.format()on filtered calls would eliminate the ~190x speedup and revert to near-print() costif not logger.handlers:guard is critical in 3ds Max since scripts are often re-executed in the same Python session; without it, each reload doubles the handler count and doubles Listener writes🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.