mirror of
https://github.com/status-im/react-native.git
synced 2025-01-10 01:25:39 +00:00
0c61b49f0a
Summary: RCTCache had really bad insertion performance when the cache was full due to having to LRU-sort the entries. This was making color animations very slow. I've fixed this in two ways: 1) by removing the sort and doing a linear search to remove old entries, which changes insertion perf to O(n) in the worst case instead of O(n log n) or even (n2). 2) by reducing the size of the color cache to 128 from 1024, which should be fine for normal use, without penalising animation performance. Separately, border colors were not being retained, which caused crashes when the color cache was cleared. I've fixed that by retaining the border colors inside RCTView.
57 lines
1.5 KiB
Objective-C
57 lines
1.5 KiB
Objective-C
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
/**
|
|
* RCTCache is a simple LRU cache implementation, based on the API of NSCache,
|
|
* but with known, deterministic behavior. The cache will always remove items
|
|
* outside of the specified cost/count limits, and will be automatically
|
|
* cleared in the event of a memory warning.
|
|
*/
|
|
@interface RCTCache : NSCache <NSFastEnumeration>
|
|
|
|
/**
|
|
* The total number of objects currently resident in the cache.
|
|
*/
|
|
@property (nonatomic, readonly) NSUInteger count;
|
|
|
|
/**
|
|
* The total cost of the objects currently resident in the cache.
|
|
*/
|
|
@property (nonatomic, readonly) NSUInteger totalCost;
|
|
|
|
/**
|
|
* Subscripting support
|
|
*/
|
|
- (id)objectForKeyedSubscript:(id<NSCopying>)key;
|
|
- (void)setObject:(id)obj forKeyedSubscript:(id<NSCopying>)key;
|
|
|
|
/**
|
|
* Enumerate cached objects
|
|
*/
|
|
- (void)enumerateKeysAndObjectsUsingBlock:(void (^)(id key, id obj, BOOL *stop))block;
|
|
|
|
@end
|
|
|
|
@protocol RCTCacheDelegate <NSCacheDelegate>
|
|
@optional
|
|
|
|
/**
|
|
* Should the specified object be evicted from the cache?
|
|
*/
|
|
- (BOOL)cache:(RCTCache *)cache shouldEvictObject:(id)entry;
|
|
|
|
/**
|
|
* The specified object is about to be evicted from the cache.
|
|
*/
|
|
- (void)cache:(RCTCache *)cache willEvictObject:(id)entry;
|
|
|
|
@end
|