This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Implement push rule evaluation in Rust. #13838
Merged
Merged
Changes from 34 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
c2d0c27
Implement push rules as Rust native types.
erikjohnston dcea8d8
Remove python baserules
erikjohnston 62caed9
Newsfile
erikjohnston 071953f
Update rust/src/push/mod.rs
erikjohnston 6605754
Merge remote-tracking branch 'origin/develop' into erikj/rust_push_rules
erikjohnston 4d97349
Code review
erikjohnston e828b34
Apply suggestions from code review
erikjohnston 47a3dcf
Apply suggestions from code review
erikjohnston 68689fa
Apply suggestions from code review
erikjohnston a109a77
Remove newsfile
erikjohnston dbeb21b
Remove old todo
erikjohnston 0e10bb3
Swap actions
erikjohnston 1e05843
Add back module docstring
erikjohnston 2945dc0
Merge remote-tracking branch 'origin/develop' into erikj/rust_push_rules
erikjohnston 415bbd6
Remove debug logging
erikjohnston 86515a9
Handle unrecognized actions
erikjohnston b57be51
Correctly handle unknwon conditions
erikjohnston a691a2d
Lint
erikjohnston b730876
Implement push rule evaluation in Rust
erikjohnston d62a7ec
Ignore unknown conditions to fix unit tests
erikjohnston 65f55a2
Update rust/src/push/evaluator.rs
erikjohnston b7ed027
Merge remote-tracking branch 'origin/develop' into erikj/rust_push_eval2
erikjohnston e75b755
Newsfile
erikjohnston bc3b216
Fix rust test
erikjohnston da1dc66
Fast path
erikjohnston 42ab02e
Benchmarks
erikjohnston 4da5b04
Merge remote-tracking branch 'origin/develop' into erikj/rust_push_eval2
erikjohnston e6d9341
Speed up
erikjohnston bef2298
Add a Matcher type
erikjohnston c51bf1e
Tidy up
erikjohnston 307e77a
Remove unnecessary optimisation
erikjohnston f760ada
Comment
erikjohnston 9df6d37
clippy
erikjohnston e4cd075
Copyright headers
erikjohnston 0035f14
Update rust/Cargo.toml
erikjohnston a503245
Merge remote-tracking branch 'origin/develop' into erikj/rust_push_eval2
erikjohnston 1034e7f
Review comments
erikjohnston de494f2
Fix merge
erikjohnston 23b307d
Apply suggestions from code review
erikjohnston 09b728d
Fix test
erikjohnston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Port push rules to using Rust. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
// Copyright 2022 The Matrix.org Foundation C.I.C. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#![feature(test)] | ||
use synapse::push::{ | ||
evaluator::PushRuleEvaluator, Condition, EventMatchCondition, FilteredPushRules, PushRules, | ||
}; | ||
use test::Bencher; | ||
|
||
extern crate test; | ||
|
||
#[bench] | ||
fn bench_match_exact(b: &mut Bencher) { | ||
let flattened_keys = [ | ||
("type".to_string(), "m.text".to_string()), | ||
("room_id".to_string(), "!room:server".to_string()), | ||
("content.body".to_string(), "test message".to_string()), | ||
] | ||
.into_iter() | ||
.collect(); | ||
|
||
let eval = PushRuleEvaluator::py_new( | ||
flattened_keys, | ||
10, | ||
0, | ||
Default::default(), | ||
Default::default(), | ||
true, | ||
) | ||
.unwrap(); | ||
|
||
let condition = Condition::Known(synapse::push::KnownCondition::EventMatch( | ||
EventMatchCondition { | ||
key: "room_id".into(), | ||
pattern: Some("!room:server".into()), | ||
pattern_type: None, | ||
}, | ||
)); | ||
|
||
let matched = eval.match_condition(&condition, None, None).unwrap(); | ||
assert!(matched, "Didn't match"); | ||
|
||
b.iter(|| eval.match_condition(&condition, None, None).unwrap()); | ||
} | ||
|
||
#[bench] | ||
fn bench_match_word(b: &mut Bencher) { | ||
let flattened_keys = [ | ||
("type".to_string(), "m.text".to_string()), | ||
("room_id".to_string(), "!room:server".to_string()), | ||
("content.body".to_string(), "test message".to_string()), | ||
] | ||
.into_iter() | ||
.collect(); | ||
|
||
let eval = PushRuleEvaluator::py_new( | ||
flattened_keys, | ||
10, | ||
0, | ||
Default::default(), | ||
Default::default(), | ||
true, | ||
) | ||
.unwrap(); | ||
|
||
let condition = Condition::Known(synapse::push::KnownCondition::EventMatch( | ||
EventMatchCondition { | ||
key: "content.body".into(), | ||
pattern: Some("test".into()), | ||
pattern_type: None, | ||
}, | ||
)); | ||
|
||
let matched = eval.match_condition(&condition, None, None).unwrap(); | ||
assert!(matched, "Didn't match"); | ||
|
||
b.iter(|| eval.match_condition(&condition, None, None).unwrap()); | ||
} | ||
|
||
#[bench] | ||
fn bench_match_word_miss(b: &mut Bencher) { | ||
let flattened_keys = [ | ||
("type".to_string(), "m.text".to_string()), | ||
("room_id".to_string(), "!room:server".to_string()), | ||
("content.body".to_string(), "test message".to_string()), | ||
] | ||
.into_iter() | ||
.collect(); | ||
|
||
let eval = PushRuleEvaluator::py_new( | ||
flattened_keys, | ||
10, | ||
0, | ||
Default::default(), | ||
Default::default(), | ||
true, | ||
) | ||
.unwrap(); | ||
|
||
let condition = Condition::Known(synapse::push::KnownCondition::EventMatch( | ||
EventMatchCondition { | ||
key: "content.body".into(), | ||
pattern: Some("foobar".into()), | ||
pattern_type: None, | ||
}, | ||
)); | ||
|
||
let matched = eval.match_condition(&condition, None, None).unwrap(); | ||
assert!(!matched, "Didn't match"); | ||
|
||
b.iter(|| eval.match_condition(&condition, None, None).unwrap()); | ||
} | ||
|
||
#[bench] | ||
fn bench_eval_message(b: &mut Bencher) { | ||
let flattened_keys = [ | ||
("type".to_string(), "m.text".to_string()), | ||
("room_id".to_string(), "!room:server".to_string()), | ||
("content.body".to_string(), "test message".to_string()), | ||
] | ||
.into_iter() | ||
.collect(); | ||
|
||
let eval = PushRuleEvaluator::py_new( | ||
flattened_keys, | ||
10, | ||
0, | ||
Default::default(), | ||
Default::default(), | ||
true, | ||
) | ||
.unwrap(); | ||
|
||
let rules = | ||
FilteredPushRules::py_new(PushRules::new(Vec::new()), Default::default(), false, false); | ||
|
||
b.iter(|| eval.run(&rules, Some("bob"), Some("person"))); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2022 The Matrix.org Foundation C.I.C. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#![feature(test)] | ||
|
||
use synapse::push::utils::{glob_to_regex, GlobMatchType}; | ||
use test::Bencher; | ||
|
||
extern crate test; | ||
|
||
#[bench] | ||
fn bench_whole(b: &mut Bencher) { | ||
b.iter(|| glob_to_regex("test", GlobMatchType::Whole)); | ||
} | ||
|
||
#[bench] | ||
fn bench_word(b: &mut Bencher) { | ||
b.iter(|| glob_to_regex("test", GlobMatchType::Word)); | ||
} | ||
|
||
#[bench] | ||
fn bench_whole_wildcard_run(b: &mut Bencher) { | ||
b.iter(|| glob_to_regex("test***??*?*?foo", GlobMatchType::Whole)); | ||
} | ||
|
||
#[bench] | ||
fn bench_word_wildcard_run(b: &mut Bencher) { | ||
b.iter(|| glob_to_regex("test***??*?*?foo", GlobMatchType::Whole)); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.