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.
This pull request optimizes unique-reference calls to Vector3, which minimizes object allocations for long call chains like this:
For the above code, the current implementation requires 4 allocations, while with this patch only one allocation is required.
Adaptability
This patch is not effective when the vector is referenced by any variables, including
$this
.This means not even calling
$this->xxx()
from a subclass ofVector3
would utilize this optimization,nor
$foo->xxx()
(even if$foo
is no longer used).This patch is not effective in some chain calls. For example, this does not optimize anything in
$event->getPlayer()->add()
.Drawbacks
This requires users to install ext-thisrc. A polyfill or cpp-based alternative may be used to support non-thisrc users.
This involves extra function call overhead in the
thisrc()
calls. ext-thisrc may be implemented at a lower level of PHP internals (rather than just as aPHP_FUNCTION
) may be useful, but that would be much more challenging.Tasks
Vector3
Vector2
thisrc()
against overhead of cloning. In particular, benchmark this in PocketMine, where not too many Vector3 calls are chained, to see if this makes anything worse.