-
Notifications
You must be signed in to change notification settings - Fork 5
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
Scala.js classes for results? #276
Comments
On further thought, I'm not sure if using native JS objects instead of case classes would actually improve anything. The benefit of doing this is that the SJS compiler won't have to emit classes for these since they are backed by native JS objects, which would reduce the size of the generated code. However, this overlooks the fact that such fields in JS native traits/objects in SJS are exempt from the name-mangling etc. that occurs during the optimization stages: they will use precisely their names as defined in the code (because it is assumed they are interopping with JS code that is using those names). So unless these field names are trivially short, I think it's very likely the size of your generated code would increase :) |
Thanks for that insight @armanbilge, I hadn't considered that. However, full field names appear at least once in the code already, in the decoder. So there may still be some improvement, depending on usage. If fields are referenced once in code, I'd say we are even WRT to names not being mangled. Of course, there will probably also be references also in the |
Yes, basically the penalty shifts from:
So you are right, if uses are actually sparse, then possibly strategy (2) will still work to your benefit. |
Sorry, one more thought about this: the next way to save code would be to use dynamic "reflectiony" derived |
Just to document some tangential results: I tried building
So, generating this increases the final artifact size in ~0.14%. I'd say it's negligible. |
Wait, how were you able to not generate the |
You can pick and choose what's generated by configuring in
In our main project ( |
That's a good suggestion, thank you. |
Right, so if you are not using these instances, then the Scala.js optimizer removes them anyway. That's why there's a negligible difference in generated JS size whether you generate them or not. |
In order to reduce the size of Scala.js code, we could add of the option of generating native Scala.js traits/classes to hold query results instead of Scala case classes.
Ideally, these would behave as facades into the JS object of the result, using
js.Array
instead ofList
,js.UndefOr
instead ofOption
, etc. We wouldn't even need aDecoder
, which means revising the baseQuery
type.Things that may be tricky:
Reusability
,Eq
andShow
instances (we do have all the info to generate them though).Focus
macro would work.It remains to be seen how much of an improvement this would be, in order to evaluate it it's worth the effort.
The text was updated successfully, but these errors were encountered: