ClojureScript

Direct field access for keyword lookup on records

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test

Description

If, via type inference, we know that a keyword is being used to lookup a field in a record, convert this to direct field access.

Example:

cljs.user=> (defrecord Foo [abcd efg])
cljs.user/Foo
cljs.user=> (def x (->Foo 1 2))
#'cljs.user/x
cljs.user=> (:abcd x)
1
cljs.user=> (set! *print-fn-bodies* true)
true
cljs.user=> (fn [] (:abcd x))
#object[ret__8748__auto__ "function (){
return cljs.user.x.abcd;
}"]
  1. CLJS-2950-0.patch
    30/Oct/18 7:51 AM
    2 kB
    Mike Fikes
  2. CLJS-2950-1.patch
    30/Oct/18 2:51 PM
    2 kB
    Mike Fikes
  3. CLJS-2950-2.patch
    30/Oct/18 3:27 PM
    3 kB
    Mike Fikes

Activity

Hide
Mike Fikes added a comment -

CLJS-2950-0.patch is a proof-of-concept illustrating the idea without yet working about compiler perf nor unit tests.

Show
Mike Fikes added a comment - CLJS-2950-0.patch is a proof-of-concept illustrating the idea without yet working about compiler perf nor unit tests.
Hide
Mike Fikes added a comment -

CLJS-2950-1.patch fixes up a couple issues:

  1. We need a literal keyword in operator position (not just a value that is inferred to be of type keyword)
  2. We need to avoid new predicates like qualified-symbol? and simple-keyword?
Show
Mike Fikes added a comment - CLJS-2950-1.patch fixes up a couple issues:
  1. We need a literal keyword in operator position (not just a value that is inferred to be of type keyword)
  2. We need to avoid new predicates like qualified-symbol? and simple-keyword?
Hide
Mike Fikes added a comment -

Speedups with CLJS-2950-1.patch for

(defrecord Foo [a b])
(simple-benchmark [x (->Foo 1 2)] (:a x) 1e8)
            V8:  4.06
  SpiderMonkey:  1.66
JavaScriptCore:  4.59
    ChakraCore: 44.75
       GraalVM:  3.79
Show
Mike Fikes added a comment - Speedups with CLJS-2950-1.patch for
(defrecord Foo [a b])
(simple-benchmark [x (->Foo 1 2)] (:a x) 1e8)
            V8:  4.06
  SpiderMonkey:  1.66
JavaScriptCore:  4.59
    ChakraCore: 44.75
       GraalVM:  3.79
Hide
Mike Fikes added a comment -

CLJS-2950-2.patch adds a test

Show
Mike Fikes added a comment - CLJS-2950-2.patch adds a test
Hide
Mike Fikes added a comment -

CLJS-2950-2.patch passes CI and in Canary.

Show
Mike Fikes added a comment - CLJS-2950-2.patch passes CI and in Canary.
Hide
Mike Fikes added a comment -

CLJS-2950-2.patch added to Patch Tender

Show
Mike Fikes added a comment - CLJS-2950-2.patch added to Patch Tender

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: