-
Notifications
You must be signed in to change notification settings - Fork 37
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
CookStar
wants to merge
5
commits into
Source-Python-Dev-Team:master
Choose a base branch
from
CookStar:speedup_function
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+46
−20
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
094c66b
Improve TypeManager.function/TypeManager.virtual_function fetch speed…
CookStar db804ed
Removed MemberFunction as an attribute.
CookStar 3d5311d
Minor fixes.
CookStar 07e7bba
Changed virtual_function to use a function cache that already exists.
CookStar 60808ea
Removed unnecessary _ptr call.
CookStar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to cause
obj
to leak forever.This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, that doesn't really make much sense. Forget about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was discarded. Here are the new test results.
Output :
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you figured already, you would get the same leak with
MethodType
. In fact, any objects inheriting fromBoost.Python.instance
are never traversed for circular references. Basically, if any objects contained into its__dict__
strongly reference the object it belongs to it will be kept hostage by the circular references. For example, the following would leak:Because the refcount of
ptr
will never reach zero, and will never be traversed by the cyclic collection.EntityMemFuncWrapper
workaround this by storing a weak proxy instead of a strong reference:Source.Python/addons/source-python/packages/source-python/entities/helpers.py
Line 104 in 12a24f4
An easy workaround here, could be to simply set
MemberFunction._this
toobj
's pointer instead ofobj
itself since that is allMemberFunction
really need to forward the calls. Though, we should probably address the issue at the root, but I'm not sure of the overall implications.EDIT: This seems to address the issue: ab33bc8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested, but based on the code, I can tell you that the
_ptr()
call on L628 is redundant sinceptr
is already aPointer
. That said, I thinkvirtual_function
could probably make great use ofCachedProperty
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Using
CachedProperty
leaksptr/_this
. Is there a way to useCachedProperty
without causing leaks?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this is what
unbound
is meant for. But now that I think about it, it seems flawed because this introduce a triangular reference that even ab33bc8 would theoretically not address.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it does not work regardless of the value of unbound.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, and it makes sense. Meaning that
cached_result
suffers from this regardless of 6d594fb. I don't remember specifically what testing I performed at the time that led me to believe otherwise but, if I had to guess, I probably usedPlayer.is_bot
with non-cached objects. This is misleading because it inherits fromEntity.__hash__
meaning that the same value is re-used for every objects that are allocated for the same player.