Optimize OOP class inheritance and element property access - #5290
Open
MohabCodeX wants to merge 3 commits into
Open
Optimize OOP class inheritance and element property access#5290MohabCodeX wants to merge 3 commits into
MohabCodeX wants to merge 3 commits into
Conversation
…rties - Flatten parent class methods, getters, and setters into derived class metatables upon registration - Preserve derived class method overrides and polymorphism without modifying Lua script semantics - Fast-path high-frequency element properties (health, dimension, interior, alpha, frozen, doubleSided, model) directly in C++ - Retain __parent lookup fallback for dynamic class runtime extensions
Member
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.
Reading and writing element properties in OOP (like
ped.healthandelement.dimension) is significantly slower than procedural calls due to runtime metatable climbing and dispatch overhead. Under continuous script loops, this caused main thread stalls, packet backlog, and client network trouble frame drops.This PR addresses this in two steps:
lua_registerclass. This turns recursive inheritance climbing into a direct O(1) table lookup on every access while preserving derived overrides.health,dimension,interior,alpha,frozen,doubleSided,model) now use a direct C++ fast-path inCLuaClassDefs::IndexandNewIndex, bypassing intermediate argument reader frames. All other properties fall through to the flattened metatables cleanly.Roadmap Context & Recommendations
Recommended merge order in the OOP and vector optimization series:
Together, these four PRs resolve ~95% of OOP and vector overhead across networking, heap allocations, GC churn, and property dispatch. The remaining ~5% (native SIMD vector bytecode math, previously explored in #1728 by @Pirulax) can be approached as a standalone future step.
Test plan
Run test_oop_benchmark.zip resource.
Benchmarks (100,000 Iterations)
.health.dimension.armor(Fallthrough).health = 100