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

[JSONSelection] Remove &mut errors: IndexSet<ApplyToError> from apply_to_path method signatures #6003

Merged
merged 6 commits into from
Sep 17, 2024

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Sep 13, 2024

Following up on this suggestion from @nicholascioli: #5762 (comment)

The apply_to_path method used to have more than one mutable parameter (input_path as well as errors), but now that input_path is immutable, I agree it's cleaner to go all the way and avoid any mutable parameters, so apply_to_path can be a pure function.

One big benefit of this refactoring is that each apply_to_path method now returns just the errors resulting from the subtree that it handled, whereas the previous &mut errors: IndexSet<ApplyToError> strategy made it difficult to know which errors came from which apply_to_path method call. This will help if we ever decide to memoize the results of apply_to_path methods, or if we want to expose ApplyToErrors for processing by -> methods (imagine some sort of ->catch handler that captures/handles errors from further down its PathList chain).

As discussed in #5987 (comment), there might not be much point in deduplicating errors now, since their path and range information effectively makes them all unique, but if we decide to stop the deduplication that's now an easy change within JSONSelection::apply_with_vars.

These changes should be entirely an implementation detail. As evidence for this claim, I did not have to change any tests.

@benjamn benjamn self-assigned this Sep 13, 2024
@benjamn benjamn requested review from nicholascioli and a team as code owners September 13, 2024 21:05
@router-perf
Copy link

router-perf bot commented Sep 13, 2024

CI performance tests

  • connectors-const - Connectors stress test that runs with a constant number of users
  • const - Basic stress test that runs with a constant number of users
  • demand-control-instrumented - A copy of the step test, but with demand control monitoring and metrics enabled
  • demand-control-uninstrumented - A copy of the step test, but with demand control monitoring enabled
  • enhanced-signature - Enhanced signature enabled
  • events - Stress test for events with a lot of users and deduplication ENABLED
  • events_big_cap_high_rate - Stress test for events with a lot of users, deduplication enabled and high rate event with a big queue capacity
  • events_big_cap_high_rate_callback - Stress test for events with a lot of users, deduplication enabled and high rate event with a big queue capacity using callback mode
  • events_callback - Stress test for events with a lot of users and deduplication ENABLED in callback mode
  • events_without_dedup - Stress test for events with a lot of users and deduplication DISABLED
  • events_without_dedup_callback - Stress test for events with a lot of users and deduplication DISABLED using callback mode
  • extended-reference-mode - Extended reference mode enabled
  • large-request - Stress test with a 1 MB request payload
  • no-tracing - Basic stress test, no tracing
  • reload - Reload test over a long period of time at a constant rate of users
  • step-jemalloc-tuning - Clone of the basic stress test for jemalloc tuning
  • step-local-metrics - Field stats that are generated from the router rather than FTV1
  • step-with-prometheus - A copy of the step test with the Prometheus metrics exporter enabled
  • step - Basic stress test that steps up the number of users over time
  • xlarge-request - Stress test with 10 MB request payload
  • xxlarge-request - Stress test with 100 MB request payload

@benjamn benjamn force-pushed the benjamn/JSONSelection-avoid-mutable-errors-IndexSet branch from 064973b to 20beea1 Compare September 13, 2024 21:14
Copy link
Member

@dylan-apollo dylan-apollo left a comment

Choose a reason for hiding this comment

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

The more functional style feels much nicer to me, thanks! I think it will be a more efficient in the error case to switch to passing owned values instead of references which we reallocate on. Might shake up too many other things, though, so if it ends up being a mess, we can stick with this.

Comment on lines +158 to +161
// Rust doesn't allow implementing methods directly on tuples like
// (Option<JSON>, Vec<ApplyToError>), so we define a trait to provide the
// methods we need, and implement the trait for the tuple in question.
pub(super) trait ApplyToResultMethods {
Copy link
Member

Choose a reason for hiding this comment

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

Nice trick, I always forget that I can hack in methods like this

@benjamn benjamn force-pushed the benjamn/JSONSelection-avoid-mutable-errors-IndexSet branch from 20beea1 to 1a44860 Compare September 17, 2024 17:21
@benjamn benjamn merged commit 8be062e into next Sep 17, 2024
11 checks passed
@benjamn benjamn deleted the benjamn/JSONSelection-avoid-mutable-errors-IndexSet branch September 17, 2024 17:46
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.

3 participants