[ASDisplayNode] Optimize -setNeedsDisplay, deep mutable array copies.

These optimizations are surprisingly impactful.  -setNeedsDisplay being called
for every node triggered cancelAsyncDisplay, locking, and memory management overhead
that is completely avoidable because Core Animation triggers first display automatically.

The mutable array copy optimizations reduced this key cost by over 10x, from 52ms to 5ms
on an iPad Air 2 / A8X with a real-world test case.
This commit is contained in:
Scott Goodson
2016-02-28 20:54:56 -08:00
parent 3671f5cbc5
commit eac85b6c9a
5 changed files with 60 additions and 39 deletions

View File

@@ -18,8 +18,14 @@
ASDISPLAYNODE_EXTERN_C_BEGIN
/**
* Deep muutable copy of multidimensional array.
* It will recursively do the multiple copy for each subarray.
* Deep mutable copy of an array that contains arrays, which contain objects. It will go one level deep into the array to copy.
* This method is substantially faster than the generalized version, e.g. about 10x faster, so use it whenever it fits the need.
*/
extern NSMutableArray<NSMutableArray *> *ASTwoDimensionalArrayDeepMutableCopy(NSArray<NSArray *> *array);
/**
* Deep mutable copy of multidimensional array. This is completely generalized and supports copying mixed-depth arrays,
* where some subarrays might contain both elements and other subarrays. It will recursively do the multiple copy for each subarray.
*/
extern NSObject<NSCopying> *ASMultidimensionalArrayDeepMutableCopy(NSObject<NSCopying> *obj);