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

All filter optimization #7300

Merged
merged 3 commits into from
Sep 28, 2023
Merged

Conversation

Cali0707
Copy link
Member

Fixes #7147

Proposed Changes

  • Dynamically optimize the ordering of the All filter so that it fails faster when possible

The results of this optimization are:

benchmark                                                                                        old ns/op     new ns/op     delta
BenchmarkAllFilter/Creation:_All_filter_with_exact_filter_test-8                                 86.2          553           +541.31%
BenchmarkAllFilter/Run:_All_filter_with_exact_filter_test-8                                      892           847           -5.04%
BenchmarkAllFilter/Creation:_All_filter_match_all_subfilters-8                                   117           659           +461.41%
BenchmarkAllFilter/Run:_All_filter_match_all_subfilters-8                                        2416          2117          -12.38%
BenchmarkAllFilter/Creation:_All_filter_no_1_match_at_end_of_array-8                             114           684           +497.82%
BenchmarkAllFilter/Run:_All_filter_no_1_match_at_end_of_array-8                                  1008          1091          +8.23%
BenchmarkAllFilter/Creation:_All_filter_no_1_match_at_start_of_array-8                           102           706           +589.17%
BenchmarkAllFilter/Run:_All_filter_no_1_match_at_start_of_array-8                                1460          1086          -25.62%
BenchmarkAllFilter/Creation:_All_filter_with_multiple_exact_filters_that_match-8                 106           710           +569.72%
BenchmarkAllFilter/Run:_All_filter_with_multiple_exact_filters_that_match-8                      2488          1960          -21.22%
BenchmarkAllFilter/Creation:_All_filter_with_one_non-matching_filter_in_the_middle-8             124           680           +448.91%
BenchmarkAllFilter/Run:_All_filter_with_one_non-matching_filter_in_the_middle-8                  1482          1098          -25.91%
BenchmarkAllFilter/Creation:_All_filter_with_one_non-matching_filter_at_the_end-8                111           714           +541.15%
BenchmarkAllFilter/Run:_All_filter_with_one_non-matching_filter_at_the_end-8                     1940          1091          -43.76%
BenchmarkAllFilter/Creation:_All_filter_with_all_non-matching_filters-8                          93.7          691           +637.81%
BenchmarkAllFilter/Run:_All_filter_with_all_non-matching_filters-8                               1095          1098          +0.27%
BenchmarkAllFilter/Creation:_All_filter_with_large_number_of_sub-filters_that_match-8            3487          10278         +194.75%
BenchmarkAllFilter/Run:_All_filter_with_large_number_of_sub-filters_that_match-8                 458423        520555        +13.55%
BenchmarkAllFilter/Creation:_All_filter_with_large_number_of_sub-filters_that_do_not_match-8     3736          10079         +169.78%
BenchmarkAllFilter/Run:_All_filter_with_large_number_of_sub-filters_that_do_not_match-8          936           1097          +17.15%
BenchmarkAllFilter/Creation:_All_filter_with_alternating_matching_and_non-matching_filters-8     3723          10069         +170.45%
BenchmarkAllFilter/Run:_All_filter_with_alternating_matching_and_non-matching_filters-8          1487          1095          -26.36%

benchmark                                                                                        old allocs     new allocs     delta
BenchmarkAllFilter/Creation:_All_filter_with_exact_filter_test-8                                 2              5              +150.00%
BenchmarkAllFilter/Run:_All_filter_with_exact_filter_test-8                                      8              7              -12.50%
BenchmarkAllFilter/Creation:_All_filter_match_all_subfilters-8                                   2              5              +150.00%
BenchmarkAllFilter/Run:_All_filter_match_all_subfilters-8                                        21             20             -4.76%
BenchmarkAllFilter/Creation:_All_filter_no_1_match_at_end_of_array-8                             2              5              +150.00%
BenchmarkAllFilter/Run:_All_filter_no_1_match_at_end_of_array-8                                  9              8              -11.11%
BenchmarkAllFilter/Creation:_All_filter_no_1_match_at_start_of_array-8                           2              5              +150.00%
BenchmarkAllFilter/Run:_All_filter_no_1_match_at_start_of_array-8                                13             8              -38.46%
BenchmarkAllFilter/Creation:_All_filter_with_multiple_exact_filters_that_match-8                 2              5              +150.00%
BenchmarkAllFilter/Run:_All_filter_with_multiple_exact_filters_that_match-8                      19             18             -5.26%
BenchmarkAllFilter/Creation:_All_filter_with_one_non-matching_filter_in_the_middle-8             2              5              +150.00%
BenchmarkAllFilter/Run:_All_filter_with_one_non-matching_filter_in_the_middle-8                  13             8              -38.46%
BenchmarkAllFilter/Creation:_All_filter_with_one_non-matching_filter_at_the_end-8                2              5              +150.00%
BenchmarkAllFilter/Run:_All_filter_with_one_non-matching_filter_at_the_end-8                     17             8              -52.94%
BenchmarkAllFilter/Creation:_All_filter_with_all_non-matching_filters-8                          2              5              +150.00%
BenchmarkAllFilter/Run:_All_filter_with_all_non-matching_filters-8                               9              8              -11.11%
BenchmarkAllFilter/Creation:_All_filter_with_large_number_of_sub-filters_that_match-8            2              5              +150.00%
BenchmarkAllFilter/Run:_All_filter_with_large_number_of_sub-filters_that_match-8                 4004           4003           -0.02%
BenchmarkAllFilter/Creation:_All_filter_with_large_number_of_sub-filters_that_do_not_match-8     2              5              +150.00%
BenchmarkAllFilter/Run:_All_filter_with_large_number_of_sub-filters_that_do_not_match-8          9              8              -11.11%
BenchmarkAllFilter/Creation:_All_filter_with_alternating_matching_and_non-matching_filters-8     2              5              +150.00%
BenchmarkAllFilter/Run:_All_filter_with_alternating_matching_and_non-matching_filters-8          13             8              -38.46%

benchmark                                                                                        old bytes     new bytes     delta
BenchmarkAllFilter/Creation:_All_filter_with_exact_filter_test-8                                 40            296           +640.00%
BenchmarkAllFilter/Run:_All_filter_with_exact_filter_test-8                                      424           400           -5.66%
BenchmarkAllFilter/Creation:_All_filter_match_all_subfilters-8                                   72            352           +388.89%
BenchmarkAllFilter/Run:_All_filter_match_all_subfilters-8                                        976           952           -2.46%
BenchmarkAllFilter/Creation:_All_filter_no_1_match_at_end_of_array-8                             72            352           +388.89%
BenchmarkAllFilter/Run:_All_filter_no_1_match_at_end_of_array-8                                  448           424           -5.36%
BenchmarkAllFilter/Creation:_All_filter_no_1_match_at_start_of_array-8                           72            352           +388.89%
BenchmarkAllFilter/Run:_All_filter_no_1_match_at_start_of_array-8                                656           424           -35.37%
BenchmarkAllFilter/Creation:_All_filter_with_multiple_exact_filters_that_match-8                 72            352           +388.89%
BenchmarkAllFilter/Run:_All_filter_with_multiple_exact_filters_that_match-8                      920           896           -2.61%
BenchmarkAllFilter/Creation:_All_filter_with_one_non-matching_filter_in_the_middle-8             72            352           +388.89%
BenchmarkAllFilter/Run:_All_filter_with_one_non-matching_filter_in_the_middle-8                  656           424           -35.37%
BenchmarkAllFilter/Creation:_All_filter_with_one_non-matching_filter_at_the_end-8                72            352           +388.89%
BenchmarkAllFilter/Run:_All_filter_with_one_non-matching_filter_at_the_end-8                     864           424           -50.93%
BenchmarkAllFilter/Creation:_All_filter_with_all_non-matching_filters-8                          56            320           +471.43%
BenchmarkAllFilter/Run:_All_filter_with_all_non-matching_filters-8                               448           424           -5.36%
BenchmarkAllFilter/Creation:_All_filter_with_large_number_of_sub-filters_that_match-8            16408         24848         +51.44%
BenchmarkAllFilter/Run:_All_filter_with_large_number_of_sub-filters_that_match-8                 208217        208193        -0.01%
BenchmarkAllFilter/Creation:_All_filter_with_large_number_of_sub-filters_that_do_not_match-8     16408         24848         +51.44%
BenchmarkAllFilter/Run:_All_filter_with_large_number_of_sub-filters_that_do_not_match-8          448           424           -5.36%
BenchmarkAllFilter/Creation:_All_filter_with_alternating_matching_and_non-matching_filters-8     16408         24848         +51.44%
BenchmarkAllFilter/Run:_All_filter_with_alternating_matching_and_non-matching_filters-8          656           424           -35.37%

However, it is worth noting that the "Creation" time actually measures creation and deletion time because I needed to clean up the goroutines.

Pre-review Checklist

  • At least 80% unit test coverage
  • E2E tests for any new behavior
  • Docs PR for any user-facing impact
  • Spec PR for any new API feature
  • Conformance test for any change to the spec

Release Note

The all filter now dynamically optimizes its ordering to improve performance

@knative-prow knative-prow bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 26, 2023
@Cali0707
Copy link
Member Author

/cc @pierDipi @creydr @matzew

@codecov
Copy link

codecov bot commented Sep 26, 2023

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (f10a44d) 77.64% compared to head (54d6672) 77.65%.
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7300   +/-   ##
=======================================
  Coverage   77.64%   77.65%           
=======================================
  Files         250      250           
  Lines       13436    13473   +37     
=======================================
+ Hits        10432    10462   +30     
- Misses       2480     2487    +7     
  Partials      524      524           
Files Coverage Δ
pkg/eventfilter/subscriptionsapi/all_filter.go 78.00% <74.41%> (-14.31%) ⬇️

... and 6 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

}
}

func (filter *allFilter) optimize(swapIdx int) {
Copy link
Member

Choose a reason for hiding this comment

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

not sure i like the generic optimize func name...
can we add a bit why it does the swap?

Comment on lines 39 to 40
c chan int
d chan bool
Copy link
Member

Choose a reason for hiding this comment

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

More auto-describing names than c or d?

// Short circuit to optimize it
if res == eventfilter.FailFilter {
filter.c <- i
Copy link
Member

@pierDipi pierDipi Sep 27, 2023

Choose a reason for hiding this comment

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

I'm worried about this could block if the background gorouting is not listening at that point, I think we need buffering (with size 1 seems fine) and avoid blocking when the buffer is full

@Cali0707 Cali0707 requested review from pierDipi and matzew September 27, 2023 14:25
Copy link
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

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

/lgtm

/hold for @matzew

@knative-prow knative-prow bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 27, 2023
@knative-prow knative-prow bot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 27, 2023
Copy link
Member

@matzew matzew left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

/unhold

@knative-prow knative-prow bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 28, 2023
@knative-prow
Copy link

knative-prow bot commented Sep 28, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Cali0707, matzew, pierDipi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot merged commit 55092a0 into knative:main Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Event Filtering: Investigate Initial Benchmark Results
3 participants