You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The above code will call bridge.deserialize twice. If user3 is an array and there are many attributes of the User3 type, will it affect performance?
Would it be better to cache the data after Defaults[.user3] is executed once?
extensionDefaults.Serializable{....staticfunc toValue(_ anyObject:Any)->Self?{// Return directly if `anyObject` can cast to Value, since it means `Value` is a natively supported type.
if
isNativelySupportedType,let anyObject = anyObject as?Self{return anyObject
}else if let value = bridge.deserialize(anyObject as?Serializable){return value as?Self}returnnil}....
The text was updated successfully, but these errors were encountered:
It can affect performance yes, if the data is large and you're calling it many times in a loop. But in common cases, it should not be a problem. You should not store huge amounts of data in UserDefaults anyway.
I do think we should look into caching the deserialized data using an LRU cache.
Actually, the first thing we could do is to simply cache all calls for 5 seconds. That way, we can make sure that we don't waste time on deserializing things that are called in a loop.
sindresorhus
changed the title
If it is a custom type, deserialize will be called every time it is used, will it affect performance?
Cache bridge deserialization
Jun 20, 2023
The above code will call
bridge.deserialize
twice. If user3 is an array and there are many attributes of the User3 type, will it affect performance?Would it be better to cache the data after Defaults[.user3] is executed once?
The text was updated successfully, but these errors were encountered: