[Performance] on_key rebuilds Key/InputState enum members on every keypress #344
Labels
No labels
Alpha Release Requirement
Bugfix
Demo Target
Documentation
Major Feature
Minor Feature
priority:tier1-active
priority:tier2-foundation
priority:tier3-future
priority:tier4-deferred
Refactoring & Cleanup
system:animation
system:documentation
system:grid
system:input
system:performance
system:procgen
system:python-binding
system:rendering
system:ui-hierarchy
Tiny Feature
workflow:blocked
workflow:needs-benchmark
workflow:needs-documentation
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
john/McRogueFace#344
Loading…
Add table
Add a link
Reference in a new issue
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?
Problem
PyScene's key handler constructs a fresh IntEnum member on every keypress for both the key and the action:PyObject_CallFunction(PyKey::key_enum_class, "i", ...)(src/PySceneObject.cpp:362)PyObject_CallFunction(PyInputState::input_state_enum_class, "i", ...)(src/PySceneObject.cpp:373)IntEnum members are immutable singletons, so calling the enum class per event re-does the member lookup/allocation ceremony each time.
Proposed fix
Pre-build the enum members once into a lookup table (array/dict indexed by key code and input state) and return the cached
PyObject*(INCREF'd) per event.Priority note
Frequency is per-input, not per-frame, so this is a smaller win than #(animation) / #(scene-update) — filing for completeness in the same hot-path cleanup sweep. Same class of fix as #331.
Benchmark
Measure enum-member acquisition cost in isolation, before/after. Add to
tests/benchmarks/.