Skip to content
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

Consider better support for DCE #34

Open
rauhs opened this issue Jul 1, 2017 · 1 comment
Open

Consider better support for DCE #34

rauhs opened this issue Jul 1, 2017 · 1 comment

Comments

@rauhs
Copy link

rauhs commented Jul 1, 2017

Currently, because of the way the writer is set up, Google Closure will not DCE any CLJS core data structures that are otherwise unused by the developer.

Though, transit-js already support dynamically looking up an alias on the object itself. Thus by adding the alias to the prototype of the types, it'd enable proper DCE on lesser used types.

So by using, for instance:

(goog.object/set (.-prototype PersistentQueueSeq) "transitTag" List)
(goog.object/set (.-prototype PersistentQueue) "transitTag" List)
(goog.object/set (.-prototype PersistentTreeSet) "transitTag" PersistentHashSet)

And removing the entries from the map in transito.core/writer, we enable DCE without losing any functionality.

This also works fine with GCC's advanced minification.

Edit: Should probably not reuse the types since user's may provide customs handler for types in which case the alias could fail. We could introduce some simple dummy deftypes that can for sure handle the conversion and alias it to those instead.

So:

(deftype GenericListHandler [])
(deftype GenericSetHandler [])
(goog.object/set (.-prototype PersistentQueueSeq) "transitTag" GenericListHandler)
(goog.object/set (.-prototype PersistentQueue) "transitTag" GenericListHandler)
(goog.object/set (.-prototype PersistentTreeSet) "transitTag" GenericSetHandler)

;; Then in the writer:
(merge
           {GenericListHandler list-handler
            GenericSetHandler set-handler
          .....})
@swannodette
Copy link
Collaborator

Will think about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants