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

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

Open
borkdude opened this issue Dec 1, 2021 · 1 comment

Comments

@borkdude
Copy link
Collaborator

borkdude commented Dec 1, 2021

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.

@logseq-cldwalker
Copy link

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

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