Skip to content

[perf] Optimize m.instrument/clj-collect!#1295

Open
alexander-yakushev wants to merge 2 commits into
metosin:masterfrom
alexander-yakushev:perf-collect
Open

[perf] Optimize m.instrument/clj-collect!#1295
alexander-yakushev wants to merge 2 commits into
metosin:masterfrom
alexander-yakushev:perf-collect

Conversation

@alexander-yakushev

Copy link
Copy Markdown
Contributor

This is minor, but filter-key is so inefficient that it got my attention. On a project like Metabase that has a few thousand namespaces, calling (clj-collect! {:ns (all-ns)}) generates a lot of unnecessary garbage and slightly slows down the initialization.

Before:
Time per call: 534.50 ms   Alloc per call: 318,043,024b

After:
Time per call: 44.75 ms   Alloc per call: 13,792,652b

@alexander-yakushev alexander-yakushev force-pushed the perf-collect branch 2 times, most recently from 06ed5b0 to 4910690 Compare June 28, 2026 18:32
Comment thread src/malli/instrument.clj Outdated
Co-authored-by: Ambrose Bonnaire-Sergeant <ambrose@ambrosebs.com>
@frenchy64

Copy link
Copy Markdown
Collaborator

Is there any hope of factoring out a helper to improve readability while preserving perf? I'm thinking -ns-publics that returns an eduction of public vars, that we then reduce or transducer over.

@alexander-yakushev

Copy link
Copy Markdown
Contributor Author

I've just tried it, but some of the efficiency is gone this way because IKVReduce doesn't play along with eductions and such, and the transducing in general. You would need to iterate over MapEntries in a map, and that is an overheady thing on its own.

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