Repository navigation
RCTBorderDrawing: Cache results to save resources - #15281
Adlai-Holler wants to merge 3 commits into
Conversation
| CGContextSetLineWidth(ctx, lineWidth); | ||
| CGContextSetLineDash(ctx, 0, dashLengths, sizeof(dashLengths) / sizeof(*dashLengths)); | ||
|
|
||
| CGContextSetStrokeColorWithColor(ctx, [UIColor yellowColor].CGColor); |
There was a problem hiding this comment.
I took this out because it looks like it was there by mistake. The stroke color gets overwritten two lines down, before the next draw operation.
| RCTGetRGBAColorComponents(borderColors.right, borderParams.rightColors); | ||
| RCTGetRGBAColorComponents(backgroundColor, borderParams.backgroundColors); | ||
|
|
||
| return [NSValue valueWithBytes:&borderParams objCType:@encode(typeof(borderParams))]; |
There was a problem hiding this comment.
You could use NSData here, and it would actually be slightly faster since the isEqual: wouldn't have to check the underlying type. But it also means another heap allocation – NSValue stores the data on the object itself instead of pointing into the heap. Plus it just feels more purpose-built.
| BOOL drawToEdge) | ||
| { | ||
| // Important that this struct is aligned on all architectures, else | ||
| // the compiler can insert garbage into the padding and corrupt our hash. |
There was a problem hiding this comment.
Can we enforce this using a compiler pragma somehow?
There was a problem hiding this comment.
Yep we can, I initially chose not to for the sake of visual cleanliness but thanks for the feedback, safety is king. Ill drop it in later today.
| } | ||
|
|
||
| static void RCTGetRGBAColorComponents(CGColorRef color, CGFloat rgba[4]) | ||
| void RCTGetRGBAColorComponents(CGColorRef color, CGFloat rgba[4]) |
There was a problem hiding this comment.
Is this an expensive operation? Should we try to normalize the UIColor to this and then use it across the whole border rendering operation?
There was a problem hiding this comment.
It's inexpensive, almost never showed up at 1ms sampling on my iPhone 6 so I'd stick with the CGColor.
|
Looks good to me. I'll have @shergin take a look as well once he's back from vacation. |
shergin
left a comment
There was a problem hiding this comment.
This is fantastic! Just couple of nits. 😄
| BOOL drawToEdge) | ||
| { | ||
| // Important that this struct is not padded on any architecture, else | ||
| // there can be garbage in the padding that corrupts our hash. |
There was a problem hiding this comment.
This is not technically hash, so we should not call it hash.
| borderImageCache = [NSCache new]; | ||
| }); | ||
|
|
||
| if (borderStyle == RCTBorderStyleUnset) { |
There was a problem hiding this comment.
I would split this function to two: RCTGetBorderImage and RCTGetCachedBorderImage.
|
@Adlai-Holler I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project. |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions. |
|
seems like something we want to ship. better not let this go stale. @Adlai-Holler can you update as per @shergin's review? |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions. |
Hi folks. When profiling RNTester on master (688c74) on my iPhone 6 10.3.3 scrolling up and down the grid view example for 10 seconds, average of 3 runs, this patch reduced
RCTGetBorderImagefrom 34ms to 4ms. I didn't look at memory consumption but presumably it lowered that as well.This is a pretty strong effect but the grid view example is pretty border-heavy so you may get less on other screens. Your call. Love your work!