sci icon indicating copy to clipboard operation
sci copied to clipboard

Can we "add" to native CLJS protocols like ILookup without perf overhead?

Open borkdude opened this issue 4 years ago • 1 comments

SCI contains some protocols like IDeref that users are able to implement in scripts. However, this comes with some perf overhead. Protocols are currently represented as multi-methods in SCI (this is an implementation detail). It seems in CLJS you're able to add to a protocol at runtime, by manipulating objects.

cljs.user=> (extend-type string ILookup (-lookup [this k] k))
nil
cljs.user=> (goog.object/getKeys -lookup)
#js ["cljs$core$IFn$_invoke$arity$2" "cljs$core$IFn$_invoke$arity$3" "cljs$lang$maxFixedArity" "string"]
cljs.user=> (goog.object/getKeys ILookup)
#js ["string"]

If SCI, by permission of the SCI users of course, has access to the native protocol, perhaps we can support extending ILookup etc in user space without much perf overhead.

borkdude avatar Dec 01 '21 22:12 borkdude

Hi. I'd vote for sci (and nbb) to be able to support this one day. An example extend-type that would benefit from supporting native CLJS protocols - https://github.com/logseq/logseq/blob/dddd937b535fe887777d6e330fd75cf503587103/deps/db/src/logseq/db/frontend/entity_plus.cljs#L28-L56

logseq-cldwalker avatar Jan 11 '24 15:01 logseq-cldwalker