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

New public api should support inlining #8

Closed
ikitommi opened this issue Oct 3, 2017 · 2 comments
Closed

New public api should support inlining #8

ikitommi opened this issue Oct 3, 2017 · 2 comments

Comments

@ikitommi
Copy link
Member

ikitommi commented Oct 3, 2017

Make things snappier by inlining all the public-api functions like this (would emit same amount of code - a good candidate for inlining):

(defn write-value-as-string
  "Encode a value as a JSON string.

  To configure, pass in an ObjectMapper created with [[object-mapper]]."
  ([object]
   (.writeValueAsString +default-mapper+ object))
  ([object ^ObjectMapper mapper]
   (.writeValueAsString mapper object)))

example of inlining from clojure.core:

(defn =
  "Equality. Returns true if x equals y, false if not. Same as
  Java x.equals(y) except it also works for nil, and compares
  numbers and collections in a type-independent manner.  Clojure's immutable data
  structures define equals() (and thus =) as a value, not an identity,
  comparison."
  {:inline (fn [x y] `(. clojure.lang.Util equiv ~x ~y))
   :inline-arities #{2}
   :added "1.0"}
  ([x] true)
  ([x y] (clojure.lang.Util/equiv x y))
  ([x y & more]
   (if (clojure.lang.Util/equiv x y)
     (if (next more)
       (recur y (first more) (next more))
       (clojure.lang.Util/equiv y (first more)))
     false)))
@danielcompton
Copy link

Not sure if you want to go this route, but Zach Tellman has some definline code somewhere that lets you write this kind of code once, rather than copying it between the function definitions and the inline definitions.

@ikitommi
Copy link
Member Author

ikitommi commented May 4, 2018

Thanks for the tip! there is also definline in the clojure.core. Just run a set of perf tests with hand written inlining for write-value-as-string and there is no notable difference in performance. +-1ns. So, no inlining for now.

@ikitommi ikitommi closed this as completed May 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants