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

perf: Optimize validation with Malli #46485

Merged
merged 3 commits into from
Aug 6, 2024
Merged

Conversation

alexander-yakushev
Copy link
Member

This PR contains various bits and pieces that make value validation with Malli more allocation-efficient (and somewhat faster). E.g., since #46167, this PR further reduces the allocations in the DB add/sync benchmark from 20 GB to ~15 GB.

Malli is updated to the latest version to include this: metosin/malli#1079.

satisfies? is bad on hot paths because of https://clojure-goes-fast.com/blog/performance-tidbit-instanceof/, https://clojure.atlassian.net/browse/CLJ-1814.

@alexander-yakushev alexander-yakushev added the no-backport Do not backport this PR to any branch label Aug 5, 2024
@alexander-yakushev alexander-yakushev self-assigned this Aug 5, 2024
@alexander-yakushev alexander-yakushev changed the title perf: Optimize validation perf: Optimize validation with Malli Aug 5, 2024
Copy link
Contributor

@piranha piranha left a comment

Choose a reason for hiding this comment

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

Nice!

I guess the change is mostly because of Malli, and reduce-kv are a nice bonus?

@alexander-yakushev
Copy link
Member Author

The Malli improvements contribute the most, yes. But reduce-kv is also significant in a few places because plain reduce over a map creates MapEntries for each key-value pair.

@alexander-yakushev alexander-yakushev merged commit 0d517c9 into master Aug 6, 2024
118 checks passed
@alexander-yakushev alexander-yakushev deleted the opt-validation branch August 6, 2024 07:54
appleby added a commit that referenced this pull request Sep 2, 2024
src/metabase/lib/schema/util.cljc
- perf: Optimize validation with Malli #46485

src/metabase/query_processor/util.clj
- Use the new private defn #46013

-------------------------------------------------------------------------------

Disallow duplicate order-by clauses in ::lib.schema.order-by/order-bys (#47489)

* Move query-processor.util/remove-lib-uuids to lib.schema.util

This function will soon be needed in lib.schema.util in order to implement distinct order-by clause schema checking.

This function feels like it should live in lib.util instead of lib.schema.util, but that would create the following
circular import dependency since lib.util indirectly requires stuff from lib.schema.util:

  lib.schema.util -> lib.util -> lib.schema.util

* Don't create queries with duplicate order-bys in remove_replace_test.cljc

Otherwise, theses tests would fail soon when we add update the order-by schema to reject duplicates.

* Declare lib.order-by/order-bys to return ::lib.schema.order-by/order-bys

Previously it inlined the schema instead.

* Disallow duplicate order-by clauses in ::lib.schema.order-by/order-bys

Fixes: 39384
appleby added a commit that referenced this pull request Sep 2, 2024
…y/order-bys" #47532

Resolved minor conflicts in the following files due to unbackported PRs

src/metabase/lib/schema/util.cljc
- perf: Optimize validation with Malli #46485

src/metabase/query_processor/util.clj
- Use the new private defn #46013

-------------------------------------------------------------------------------

Disallow duplicate order-by clauses in ::lib.schema.order-by/order-bys (#47489)

* Move query-processor.util/remove-lib-uuids to lib.schema.util

This function will soon be needed in lib.schema.util in order to implement distinct order-by clause schema checking.

This function feels like it should live in lib.util instead of lib.schema.util, but that would create the following
circular import dependency since lib.util indirectly requires stuff from lib.schema.util:

  lib.schema.util -> lib.util -> lib.schema.util

* Don't create queries with duplicate order-bys in remove_replace_test.cljc

Otherwise, theses tests would fail soon when we add update the order-by schema to reject duplicates.

* Declare lib.order-by/order-bys to return ::lib.schema.order-by/order-bys

Previously it inlined the schema instead.

* Disallow duplicate order-by clauses in ::lib.schema.order-by/order-bys

Fixes: 39384

Co-authored-by: Mike Appleby <[email protected]>
@github-actions github-actions bot added this to the 0.51 milestone Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-backport Do not backport this PR to any branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants