-
Notifications
You must be signed in to change notification settings - Fork 6
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
Improve performance of encode and decode an M #35
base: main
Are you sure you want to change the base?
Conversation
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) | ||
} | ||
|
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.
@SystemFw this is the core of the thing
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) | ||
} | ||
} |
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.
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
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. |
There's been some discussion offline. General direction is good, we just need to iron out some minor details. |
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.