Closed (fixed)
Project:
Drupal core
Version:
x.y.z
Component:
base system
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
14 Dec 2005 at 17:53 UTC
Updated:
17 Jan 2006 at 19:02 UTC
Jump to comment: Most recent file
object2array() uses a foreach loop to convert object attributes to array elements. This can be done about 2.4 times faster using a simple cast (array) operator. As an additional benefit, the type check for the argument being an object can be dropped, since casting an array to an array does no harm.
Patch forthcoming.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | _41169_optimizearrayobject.patch | 9.33 KB | Chris Johnson |
| #4 | arrayobjectoptimize4.6.patch | 1006 bytes | Chris Johnson |
| #3 | arrayobjectoptimizeHead.patch | 989 bytes | Chris Johnson |
| #1 | object2array_head.patch | 691 bytes | Chris Johnson |
Comments
Comment #1
Chris Johnson commentedHere is a patch against HEAD, as of December 14, 2005.
Comment #2
Chris Johnson commentedAh, just discovered that array2object() was likewise slow. I have patched my 4.7 test system for both routines to just use cast operators (array) and (object) and tested without errors.
Will be rolling new patch combining fixes for both routines, for HEAD/4.7 and 4.6.
Comment #3
Chris Johnson commentedCombined patch against Head, December 14, 2005.
Comment #4
Chris Johnson commentedCombined patch against 4.6 branch (4.6.5, December 12, 2005).
Comment #5
kquinn commentedWouldn't it be preferable to simply remove the object2array function and change all code that calls it to simply cast instead? If the overhead of the function call is at all significant (which I believe to be the case) that seems like it would be a significant improvement.
Thanks.
Comment #6
kquinn commentedRegarding my last comment: ditto array2object.
Comment #7
dries commentedGreat catch, Chris!
Comment #8
Chris Johnson commentedOk, I will roll a patch for 4.7 only which removes the function calls and changes them all to casts.
Comment #9
dries commentedThanks!
Comment #10
Chris Johnson commentedPatch for core HEAD (as of 0523GMT on 29 December).
This will break all contrib which uses either function, since they have now been deleted.
Comment #11
dries commentedCommitted. Wil you add a note to the upgrade guide?
Comment #12
Chris Johnson commentedComment to module developer upgrade handbook posted.
Comment #13
(not verified) commented