Skip to content

Commit

Permalink
Moderately improve the micro behavior of route transform
Browse files Browse the repository at this point in the history
This commit is a follow-up to #11697. We don't actually need to iterate an
`IndexMap` repeatedly here as we never actually use the map capabilities of the
conditions field: a vec is enough. This is worth a small boost in the micro but
I suspect nothing in the macro.

If we are to actually optimize route we'll probably need to run multiple copies
of them, run an `EventArray` through it and/or dramatically improve the behavior
of `condition.check`.

Signed-off-by: Brian L. Troutwine <brian@troutwine.us>
  • Loading branch information
blt committed Mar 5, 2022
1 parent 49e80a2 commit 6b93c41
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions benches/transform/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::{collections::BTreeMap, time::Duration};

use bytes::Bytes;
use criterion::{
criterion_group, measurement::WallTime, BatchSize, BenchmarkGroup, BenchmarkId, Criterion,
SamplingMode, Throughput,
black_box, criterion_group, measurement::WallTime, BatchSize, BenchmarkGroup, BenchmarkId,
Criterion, SamplingMode, Throughput,
};
use value::Value;
use vector::transforms::{
Expand Down Expand Up @@ -158,7 +158,7 @@ fn route(c: &mut Criterion) {
(route, param.input.clone(), param.output_buffer.clone())
},
|(mut route, input, mut output_buffer)| {
route.transform(input, &mut output_buffer);
black_box(route.transform(input, &mut output_buffer));
},
BatchSize::SmallInput,
)
Expand Down
10 changes: 5 additions & 5 deletions src/transforms/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ use crate::{

#[derive(Clone)]
pub struct Route {
conditions: IndexMap<String, Condition>,
conditions: Vec<(String, Condition)>,
}

impl Route {
pub fn new(config: &RouteConfig, context: &TransformContext) -> crate::Result<Self> {
let mut conditions = IndexMap::new();
let mut conditions = Vec::with_capacity(config.route.len());
for (output_name, condition) in config.route.iter() {
let condition = condition.build(&context.enrichment_tables)?;
conditions.insert(output_name.clone(), condition);
conditions.push((output_name.clone(), condition));
}
Ok(Self { conditions })
}
Expand All @@ -38,13 +38,13 @@ impl SyncTransform for Route {
event: Event,
output: &mut vector_core::transform::TransformOutputsBuf,
) {
for (output_name, condition) in self.conditions.iter() {
for (output_name, condition) in &self.conditions {
if condition.check(&event) {
output.push_named(output_name, event.clone());
} else {
emit!(&RouteEventDiscarded {
output: output_name.as_ref()
});
})
}
}
}
Expand Down

0 comments on commit 6b93c41

Please sign in to comment.