Skip to content

Improve TypeManager.function/TypeManager.virtual_function fetch speed by using cache. #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed MemberFunction as an attribute.
Changed virtual_function to be cached as well.
  • Loading branch information
CookStar committed Jun 17, 2023
commit db804ed955a21b48270776ae47804a389588b018
29 changes: 16 additions & 13 deletions addons/source-python/packages/source-python/memory/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ def virtual_function(
if return_type not in DataType.values:
return_type = self.create_converter(return_type)

funcs = {}

class fget(object):
def __set_name__(fget_self, owner, name):
fget_self.name = name
Expand All @@ -628,22 +630,26 @@ def __get__(fget_self, obj, cls=None):
if obj is None:
return fget_self

# Create the virtual function
func = obj.make_virtual_function(
index,
convention,
args,
return_type
)
# Get the vtable address
address = obj._ptr().get_pointer().address
# Search function cache by vtable address
func = funcs.get(address, None)

if func is None:
# Create the virtual function cache it
func = obj.make_virtual_function(
index,
convention,
args,
return_type
)
funcs[address] = func

# Wrap it using MemberFunction, so we don't have to pass the this
# pointer anymore
func = MemberFunction(self, return_type, func, obj)
func.__doc__ = doc

# Set the MemberFunction as an attribute to the instance.
setattr(obj, fget_self.name, func)

return func

return fget()
Expand Down Expand Up @@ -696,9 +702,6 @@ def __get__(fget_self, obj, cls=None):
m_func = MemberFunction(self, return_type, func, obj)
m_func.__doc__ = doc

# Set the MemberFunction as an attribute to the instance.
setattr(obj, fget_self.name, m_func)

return m_func

return func
Expand Down