-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize serialization #132
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #132 +/- ##
==========================================
+ Coverage 86.19% 86.73% +0.53%
==========================================
Files 18 18
Lines 884 965 +81
==========================================
+ Hits 762 837 +75
- Misses 122 128 +6 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me, but I'm probably not the best one to approve this. Would be good to get Austin or Deniz to take a look too
I think switch can be optimized with fun tryToJSONString(_ value: AnyStruct): String? {
// Recursively serialize array & return
if value.getType().isSubtype(of: Type<[AnyStruct]>()) {
return arrayToJSONString(value as! [AnyStruct])
}
// Recursively serialize map & return
if value.getType().isSubtype(of: Type<{String: AnyStruct}>()) {
return dictToJSONString(dict: value as! {String: AnyStruct}, excludedNames: nil)
}
if let v=value as? String {
return String.join(["\"", v , "\"" ], separator: "")
}
if let v=value as? Number {
return String.join(["\"", v.toString() , "\"" ], separator: "")
}
if let v=value as? Character {
return String.join(["\"", v.toString() , "\"" ], separator: "")
}
if let v=value as? Bool {
return String.join(["\"", v?"true":"false" , "\"" ], separator: "")
}
if let v=value as? Address {
return String.join(["\"", v.toString() , "\"" ], separator: "")
}
if value==nil{
return "\"nil\""
}
return nil
} |
Thanks for the suggestions @bluesign. Some quick comparisons indicate there doesn't seem to be much of a difference between |
Yeah they are pretty much same, but less code basically, I think switch is converting to if else technically but not sure |
Related: #80
Description
Serialize.cdc
&SerializeMetadata.cdc
by replacing.concat
withString.join
<- credit to @bluesign for the suggestion.concat
(2167 gas) andString.join
(7 gas) to join 500 strings without loopingpreviewnet
fromflow.json
For contributor use:
main
branchFiles changed
in the Github PR explorer