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

Re-implement Muuntaja as Protocol #60

Merged
merged 14 commits into from Jan 16, 2018
Merged

Re-implement Muuntaja as Protocol #60

merged 14 commits into from Jan 16, 2018

Conversation

ikitommi
Copy link
Member

@ikitommi ikitommi commented Jan 15, 2018

  • Fixes Re-implement Muuntaja as a Protocol #59
  • Optimized negotiate-and-format-request (less hash-lookups)
  • Optimized path for UTF-8 with Jsonista
  • +20% better e2e throughput with middleware (Jsonista)

screen shot 2018-01-15 at 8 14 44

Copy link
Contributor

@miikka miikka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's so much code moving around that this is pretty hard to review, but it mostly looks okay. The UTF-8 optimization makes sense to me, it should be the most common path!

(.clear cache))
(.putIfAbsent cache args ret))
ret)))))
(if-not (= args empty)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this is? Always return nil if for ((fast-memoize .. f) nil)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. we need to either guard against input to the memoize or handle the nil-case within it. Without this, the ((fast-memoize .. f) nil) always misses the cache ('(nil) is not found on the cache as it returns nil and the .get returns nil. Not sure why. But the execution cost goes from ~30ns to 3000ns. For cases like "no accept-header set" etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using .getOrDefault?

(let [cache ...
      sentinel (Object.)]
  (fn [& args]
    (let [cached (.getOrDefault cache args sentinel)]
      (if (identical? sentinel cached)
         (comment compute the value)
         cached))
      

{:type type
:format format}
e)))))
(defn consumes [m]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these small public functions would benefit from docstrings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed.

@miikka
Copy link
Contributor

miikka commented Jan 16, 2018

Since this removes the Muuntaja record, should probably bump the version to 0.5.0 once this is merged.

@ikitommi
Copy link
Member Author

thans for the review, fixed those.

@ikitommi ikitommi merged commit 8e59542 into master Jan 16, 2018
@opqdonut opqdonut deleted the Protocols branch March 15, 2024 10:06
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

Successfully merging this pull request may close these issues.

None yet

2 participants