Improve TypeManager.function/TypeManager.virtual_function fetch speed by using cache. by CookStar · Pull Request #479 · Source-Python-Dev-Team/Source.Python
Repository navigation
Improve TypeManager.function/TypeManager.virtual_function fetch speed by using cache. - #479
Open
CookStar wants to merge 5 commits into Source-Python-Dev-Team:master from CookStar:speedup_function
Open
Improve TypeManager.function/TypeManager.virtual_function fetch speed by using cache. #479 CookStar wants to merge 5 commits into Source-Python-Dev-Team:master from CookStar:speedup_function
Conversation
CookStar commented Jun 14, 2023 · edited Loading
Copy link Copy Markdown
Contributor
Entity has a mechanism to speed up the retrieval of dynamic_attributes/server_classes, but TypeManager itself does not. With this improvement, instances created by TypeManager can speed up the retrieval of function/virtual_function.
In virtual_function, I tried to improve the performance by using type_info and caching, but it did not improve the performance.
Test Code (CS:GO/Linux):
import time
from memory import find_binary
from memory import make_object
from memory.manager import CustomType
from memory.manager import TypeManager
""" TypeManager.function Test"""
# _ZN9CCSPlayer12RoundRespawnEv
signature = b"\x55\x89\xE5\x56\x53\x83\xEC\x1C\x8B\x5D\x08\xFF\x35\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\x83\xC4\x10\x84\xC0\x0F\x85\x2A\x2A\x2A\x2A\x8B\x13"
# Cache signature
find_binary("server", srv_check=False)[signature]
manager = TypeManager()
class Test(CustomType, metaclass=manager):
_binary = "server"
_srv_check = False
_size = 0
_spawn = manager.function(signature)
# Cache function
Test._spawn
s = time.perf_counter()
for i in range(100000):
Test._spawn
e = time.perf_counter()
print(e-s, "Test._spawn")
# Cache function
test = Test()
test._spawn
s = time.perf_counter()
for i in range(100000):
test._spawn
e = time.perf_counter()
print(e-s, "test._spawn")
l = [Test() for i in range(100000)]
s = time.perf_counter()
for i in range(100000):
l[i]._spawn
e = time.perf_counter()
print(e-s, "Test()._spawn")
""" TypeManager.virtual_function Test"""
manager = TypeManager()
class Test(CustomType, metaclass=manager):
blind = manager.virtual_function(551, (DataType.FLOAT, DataType.FLOAT, DataType.FLOAT))
pointer = Entity.find("player").pointer
test = make_object(Test, pointer)
test.blind
s = time.perf_counter()
for i in range(100000):
test.blind
e = time.perf_counter()
print(e-s, "test.blind")
l = [make_object(Test, pointer) for i in range(100000)]
s = time.perf_counter()
for i in range(100000):
l[i].blind
e = time.perf_counter()
print(e-s, "make_object(Test, pointer).blind")
Since the implementation has changed, the test results have also changed.
Output :
TypeManager.function Test
4.355441149324179 Test._spawn
4.830625455826521 test._spawn
4.801660872995853 Test()._spawn
↓
OLD: 0.02216128632426262 Test._spawn
OLD: 0.008792959153652191 test._spawn
OLD: 0.2989997826516628 Test()._spawn
NEW: 0.023133378475904465 Test._spawn
NEW: 0.29126785323023796 test._spawn
NEW: 0.293557733297348 Test()._spaw
TypeManager.virtual_function Test
0.5497394129633904 test.blind
0.5683586820960045 make_object(Test, pointer).blind
↓
OLD: 0.008566077798604965 test.blind
OLD: 0.5120681896805763 make_object(Test, pointer).blind
NEW: 0.46108797565102577 test.blind
NEW: 0.4727563001215458 make_object(Test, pointer).blind
Improve TypeManager.function/TypeManager.virtual_function fetch speed...
094c66b
... by using cache and setattr.jordanbriere reviewed Jun 14, 2023
View reviewed changes
Comment thread addons/source-python/packages/source-python/memory/manager.py
Outdated
| m_func . __doc__ = doc | ||
|
|
||
| # Set the MemberFunction as an attribute to the instance. | ||
| setattr ( obj , fget_self . name , m_func ) |
Removed MemberFunction as an attribute.
db804ed
Changed virtual_function to be cached as well.CookStar changed the title Improve TypeManager.function/TypeManager.virtual_function fetch speed by using cache and setattr. Improve TypeManager.function/TypeManager.virtual_function fetch speed by using cache. Jun 17, 2023 CookStar force-pushed the speedup_function branch from
c197899 to
094c66b
Compare
June 17, 2023 15:54 CookStar added 2 commits June 18, 2023 01:00
Minor fixes.
3d5311d
Changed virtual_function to use a function cache that already exists.
07e7bba
CookStar
force-pushed
the
speedup_function
branch
from
a27f20f to
07e7bba
Compare
June 21, 2023 13:10
Removed unnecessary _ptr call.
60808ea
This branch has not been deployed
No deployments
Sign up for free to join this conversation on GitHub . Already have an account? Sign in to comment