-
Notifications
You must be signed in to change notification settings - Fork 390
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
Performance Degradation with AnyValue Enum #1903
Comments
lalitb
changed the title
Performance Degradation in AnyValue Enum
Performance Degradation with AnyValue Enum
Jul 2, 2024
Benchmark Codeuse std::collections::HashMap;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
fn criterion_benchmark(c: &mut Criterion) {
attributes_creation(c);
}
fn attributes_creation(c: &mut Criterion) {
c.bench_function("SmallEnum", |b| {
b.iter(|| {
let _v = black_box(SmallEnum::Int(10));
});
});
c.bench_function("MediumEnum", |b| {
b.iter(|| {
let _v = black_box(MediumEnum::Int(10));
});
});
c.bench_function("BigEnum", |b| {
b.iter(|| {
let _v = black_box(BigEnum::Int(10));
});
});
c.bench_function("BiggerEnum", |b| {
b.iter(|| {
let _v = black_box(BiggerEnum::Int(10));
});
});
}
// Size is 8 bytes
pub enum SmallEnum {
/// An integer value
Int(usize),
}
// Size is 24 bytes
pub enum MediumEnum {
/// An integer value
Int(usize),
Vector(Vec<usize>),
}
// Size is 48 bytes
pub enum BigEnum {
/// An integer value
Int(usize),
Map(HashMap<String, usize>),
}
// Size is 96 bytes
pub enum BiggerEnum {
/// An integer value
Int(usize),
Map((HashMap<String, usize>, HashMap<String, usize>)),
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches); Benchmark Results:
|
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As discussed in linked issue, There is a noticeable performance degradation when using the AnyValue enum compared to the Value enum. This needs to be investigated further.
Originally posted by @cijothomas in #1901 (comment)
The text was updated successfully, but these errors were encountered: