-
Notifications
You must be signed in to change notification settings - Fork 10
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
Use an immutable/mutable design #45
Comments
👍
👍
Can we define the "default" constructors in the parent package of
I care more about deterministic key ordering than I do duplicate keys — this is actually the reason that |
Yes this is implied in the transition
Yes, for mutable implementation a |
This all sounds good to me then! |
I haven't followed this story in enough detail to be sure that my feedback is that useful. yet, this does sound plausible and appealing. +1 to "mutable" being a much clearer name, IMO, than "safe" and "unsafe" and, as I've said before:
|
If we are talking about mirroring the collections API, could we have a common API similar to |
After some thinking in regards to the design tradeoffs of ScalaJson, I am exploring the idea of renaming
unsafe
tomutable
and doing some other changes (which mainly means removing the use of exceptions).Reasons are
LinkedList
) this performance problem is even worse. In particular the issue is with aMap
collection (specifically aMap
that retains key insertion order). There is currently no known immutable datastructure which satisfies both having key insertion order and effectively constant amortized lookup times (both by key and by index for the map). This is because the tree structure that most immutable datastructures use (for structural sharing) use branching to maintain either order OR lookup by key. Currently all implementations of such a datastructure is just a compound datastructure which maintains aVector
/HashMap
underneath. This for obvious reasons is not very performant.JArray
/JObject
where as for immutable we have to use Vector. Since browsers have optimized Javascript array for decodes, its really fast. On the other hand, a Scala.js ported immutableVector
is going to be much slowerHashMap
for Json Objects and only makes an immutable view when you try to read from the AST directly.The proposed changes will be
unsafe
tomutable
mutable
(so at least the interface is as safe as it is in in the standard implementation)immutable
and inmutable
package namespaces with the default constructors aliasing toimmutable
(just like withList
andMap
in scala collections)unsafe
Json Object, going to change from using an array ofJField
to aMap
datastructure. On Scala this will be standard mutableHashMap
where as on Scala.js this will be Javascripts ownMap
(if possible). This is so that we have the ideal data structure both for performance and for usage. This does mean we will lose the ability for parsing and retaining duplicate keys (it seems that in Scala land no one relies on this feature. OnlyJson4s
has this ability, and they actually want to change to aMap
).@sirthias @Ichoran @jvican @dwijnand @eed3si9n @travisbrown @gmethvin @farmdawgnation @SethTisue Thoughts?
The text was updated successfully, but these errors were encountered: