Improve performance of encode and decode an M#35
Draft
filosganga wants to merge 5 commits intomainfrom
Draft
Conversation
filosganga
commented
Dec 30, 2024
Comment on lines
+174
to
+183
| case class OptimizedRecord[R, A]( | ||
| fields: List[Field[R, _]], | ||
| build: List[Any] => A | ||
| ) | ||
|
|
||
| def fields[R](p: FreeApplicative[Field[R, *], R]): Schema[R] = { | ||
| val optimized = optimizeRecord(p) | ||
| Record(optimized.fields, optimized.build) | ||
| } | ||
|
|
Collaborator
Author
There was a problem hiding this comment.
@SystemFw this is the core of the thing
filosganga
commented
Dec 30, 2024
Comment on lines
+296
to
+310
| case class Record[R]( | ||
| fields: List[Field[R, ?]], | ||
| build: List[Any] => R, | ||
| fieldNames: Array[String] | ||
| ) extends Schema[R] | ||
|
|
||
| object Record { | ||
| def apply[R]( | ||
| fields: List[Field[R, ?]], | ||
| build: List[Any] => R | ||
| ): Record[R] = { | ||
| val fieldNames = fields.map(_.name).toArray | ||
| new Record(fields, build, fieldNames) | ||
| } | ||
| } |
Collaborator
Author
There was a problem hiding this comment.
I am not sure about this, I think we could replace with:
case class Record[R](or: OptimizedRecord[R,*]) extends Schema[R]
I don't believe caching fieldNames make this huge difference in the normal use cases
Collaborator
Author
|
I have moved internal/encoding and internal/decoding into the JS/JVM specific code, as the encodeRecord handles the AttributeValue directly and uses the JVM IdentityMap. |
Owner
|
There's been some discussion offline. General direction is good, we just need to iron out some minor details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fundamentally solve the FreeApplicative at schema creation and replaces it with a custom structure that is flat, avoiding to navigate the FreeApplicative structure each time we encode or decode a Record.