Specialize Js.Dict.fromArray to compile to direct JS object creation
…when possible.
A Dict is obviously a JS object at runtime, but there has been no way to create a dict in a way that compiles to a regular JS object creation. This can be a bit confusing when looking at the generated code, as well as hurt performance (albeit slightly in most cases) as creating dict objects are done dynamically via an array.
This changes so that any Js.Dict.fromArray call that is an array with static string keys can get compiled to an actual JS object creation.
@cristianoc no idea if this is the right way to go about it, feedback very welcome.
Related issues:
- https://github.com/rescript-lang/rescript-compiler/issues/6301
- https://github.com/rescript-lang/rescript-compiler/issues/2320
What about RescriptCore.Dict.fromArray?
Yeah that's a good point, we should make sure this PR handles both.
Dict should be promoted to a built in type and specialized that way instead.
@cristianoc please have a look at whether this approach is good and if the optimization is in the correct place. Maybe it could be put somewhere else?
When Core moves into the compiler (https://github.com/rescript-lang/rescript-compiler/pull/6761) then we'll change this to account for Dict.fromArray as well.