Skip to content

Consider better support for DCE #34

@rauhs

Description

@rauhs

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
          .....})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions