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

Improve map gen creation performance #948

Merged
merged 7 commits into from
Sep 6, 2023
Merged

Conversation

bsless
Copy link
Contributor

@bsless bsless commented Sep 5, 2023

This MR improves the performance for creating a map gen ~x5, mostly by removing a call to satisfies?, and further by choosing performant functions in the implementation.

Replace with extend
Single pass over entries
Use transients and eagerness when building map

TODO result generator performance is still ~3-4x slower than
gen/hash-map generator. Too many fmaps and tuples?
@ikitommi
Copy link
Member

ikitommi commented Sep 6, 2023

Thanks for the improvements! This only mainly effects (e.g. satifies?) the case where the generator is not cached, right?

;; no cache
(mg/generate [:map [:x :int] [:y :int]])

;; instance cache
(let [s (m/schema [:map [:x :int] [:y :int]])]
  (mg/generate s))
  
;; cached function
(let [g (mg/generator [:map [:x :int] [:y :int]])]
  (mg/generate g))

@ikitommi
Copy link
Member

ikitommi commented Sep 6, 2023

On my machine, merging this. Thanks!!

(p/bench (mg/generate [:map [:x :int] [:y :int]]))
;; 18,5µs => 5,6 µs (-70%)

(let [s (m/schema [:map [:x :int] [:y :int]])]
  (p/bench (mg/generate s)))
;; => 3.3µs => 2.8µs (-15%)

(let [g (mg/generator [:map [:x :int] [:y :int]])]
  (p/bench (mg/generate g)))
;; => 2.8µs => 2.6µs (-8%)

@ikitommi ikitommi merged commit bae29fb into metosin:master Sep 6, 2023
6 checks passed
@bsless
Copy link
Contributor Author

bsless commented Sep 6, 2023

Gladly :)
For reference, this is the use case that made me care about construction performance
https://github.com/bsless/fsm-test-check/blob/master/examples/add_delete_tx_malli.clj

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.

2 participants