-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Optimize SplFixedArray when magic methods aren't overridden #6552
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
Conversation
This decreases the memory usage of SplFixedArrays by 32 bytes per object on 64-bit systems (use 1 null pointer instead of 5 null pointers) If allocating a lot of arrays of size 1, memory usage was 19.44MiB before this change, and 16.24MiB after the change. Existing tests continue to pass. Subclassing SplFixedArray is already inefficient and rarely done. It checks for the existence of 5 methods every time a subclass is instantiated. (and has to switch back from C to the php vm to call those methods)
@morrisonlevi @nikic @kocsismate - any objections? |
You reduce the size of each SplFixedArray by 32 bytes, yet in the script comments it says after applying this optimization you went from 79.124MiB down to 63.124MiB, yet it only instantiates 10 SplFixedArrays. What am I missing? |
There's I ran the benchmark as a whole 10 times in the loop at the bottom |
Ah, I see. I'm not sure how common it is to instantiate more than one at a time. Pro: obviously it is more space efficient when SplFixedArray isn't inherited from (common). I will support whatever Nikita or other SPL contributors think is best, as I don't feel strongly 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.
Ideally these methods would be cached in the class_entry, but that's a larger change.
|
||
typedef struct _spl_fixedarray_object { | ||
spl_fixedarray array; | ||
spl_fixedarray_methods* methods; |
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.
spl_fixedarray_methods* methods; | |
spl_fixedarray_methods *methods; |
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 in linked commit
True - I wasn't sure if there was already a way to automatically run a C callback to modify any subclass of a class such as SplFixedArray but it didn't seem straightforward. Using two sets of handlers and different sized allocations to avoid checking |
I'd misunderstood what you meant earlier.
If a new
|
Previously, code such as subclasses of SplFixedArray would check for method overrides when instantiating the objects. This optimization was mentioned as a followup to phpGH-6552
Previously, code such as subclasses of SplFixedArray would check for method overrides when instantiating the objects. This optimization was mentioned as a followup to phpGH-6552
Previously, code such as subclasses of SplFixedArray would check for method overrides when instantiating the objects. This optimization was mentioned as a followup to GH-6552
This decreases the memory usage of SplFixedArrays by 32 bytes per object
on 64-bit systems (use 1 null pointer instead of 5 null pointers)
If allocating a lot of arrays of size 1, memory usage was 19.44MiB before this
change, and 16.24MiB after the change.
Existing tests continue to pass.
Subclassing SplFixedArray is already inefficient and rarely done - it checks for the existence of 5 methods every time a subclass is instantiated.
(and has to switch back from C to the php vm to call those methods)