ClojureScript

Add an IAtom protocol

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code

Description

Add an IAtom protocol with a -reset! method and a fast path for Atom in cljs.core/reset!.

See jsperf here - http://jsperf.com/iatom-adv

Latest chrome and firefox versions suffer ~20-30% slowdown. Older firefox versions suffer up to 60-70%.

  1. CLJS-760.patch
    03/Feb/14 6:15 PM
    2 kB
    Jamie Brandon
  2. CLJS-760.patch
    02/Feb/14 11:51 AM
    2 kB
    Jamie Brandon
  3. patch
    01/Feb/14 10:18 PM
    1 kB
    Jamie Brandon

Activity

Hide
David Nolen added a comment -

This is not a properly formatted patch - http://github.com/clojure/clojurescript/wiki/Patches.

Show
David Nolen added a comment - This is not a properly formatted patch - http://github.com/clojure/clojurescript/wiki/Patches.
Jamie Brandon made changes -
Field Original Value New Value
Attachment CLJS-760.patch [ 12743 ]
Hide
Jamie Brandon added a comment -

Fixed

Show
Jamie Brandon added a comment - Fixed
David Nolen made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
David Nolen made changes -
Status Resolved [ 5 ] Closed [ 6 ]
Hide
Jozef Wagner added a comment -

What is the rationale behind this? Do you plan to have multiple Atom types?

Show
Jozef Wagner added a comment - What is the rationale behind this? Do you plan to have multiple Atom types?
Hide
David Nolen added a comment -

There's no good reason to lock down atom behavior to the one provided by ClojureScript.

Show
David Nolen added a comment - There's no good reason to lock down atom behavior to the one provided by ClojureScript.
Hide
Jozef Wagner added a comment -

I agree that such behavior should be polymorphic, I was just surprised that it is a pressing issue in a single threaded CLJS. Clojure itself does not provide such abstraction. Anyway, if you want to get it right, I suggest also to include swap! and compare-and-set! in the protocol (in order to not lock down the sharing and change policy), and to name it something like IMutableReference, as these methods are generic enough to be used outside atom, (as atom promises additional features besides those of a simple mutable reference). See https://gist.github.com/wagjo/8786305 for inspiration.

Show
Jozef Wagner added a comment - I agree that such behavior should be polymorphic, I was just surprised that it is a pressing issue in a single threaded CLJS. Clojure itself does not provide such abstraction. Anyway, if you want to get it right, I suggest also to include swap! and compare-and-set! in the protocol (in order to not lock down the sharing and change policy), and to name it something like IMutableReference, as these methods are generic enough to be used outside atom, (as atom promises additional features besides those of a simple mutable reference). See https://gist.github.com/wagjo/8786305 for inspiration.
Hide
David Nolen added a comment -

I question the utility of compare-and-set! given most JS hosts are single threaded (but who knows? things are changing quickly in the JS world). It's something to consider in the future. IMutableReference is just more to type and I'm not really convinced it offers anything semantically over IAtom. Atoms do support more functionality but this is covered in other protocols.

Show
David Nolen added a comment - I question the utility of compare-and-set! given most JS hosts are single threaded (but who knows? things are changing quickly in the JS world). It's something to consider in the future. IMutableReference is just more to type and I'm not really convinced it offers anything semantically over IAtom. Atoms do support more functionality but this is covered in other protocols.
Hide
David Nolen added a comment -

We need to include -swap! in the IAtom protocol.

Show
David Nolen added a comment - We need to include -swap! in the IAtom protocol.
David Nolen made changes -
Status Closed [ 6 ] Reopened [ 4 ]
Resolution Completed [ 1 ]
Hide
Jozef Wagner added a comment -

The usefulness of the atom and protocols behind it should 'transcendent' the notion of single/multiple threads. Prime example is the Avout and its zk-atom and zk-ref. If e.g. implementing Avout in CLJS is a reasonable and useful thing to do, we should prepare for it by designing protocols to handle such use cases.

Show
Jozef Wagner added a comment - The usefulness of the atom and protocols behind it should 'transcendent' the notion of single/multiple threads. Prime example is the Avout and its zk-atom and zk-ref. If e.g. implementing Avout in CLJS is a reasonable and useful thing to do, we should prepare for it by designing protocols to handle such use cases.
Hide
David Nolen added a comment -

Avout is an third party library which has no relation to the direction of ClojureScript. This ticket is a conservative change that opens up the door for extending atom-like capabilities to user types, that's it. Further enhancements may or may not come in the future.

Show
David Nolen added a comment - Avout is an third party library which has no relation to the direction of ClojureScript. This ticket is a conservative change that opens up the door for extending atom-like capabilities to user types, that's it. Further enhancements may or may not come in the future.
Jamie Brandon made changes -
Attachment CLJS-760.patch [ 12747 ]
David Nolen made changes -
Resolution Completed [ 1 ]
Status Reopened [ 4 ] Resolved [ 5 ]
David Nolen made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: