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

[WIP] Box complex types in AnyValue enum #1913

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

lalitb
Copy link
Member

@lalitb lalitb commented Jul 8, 2024

Fixes #1903
Design discussion issue (if applicable) #

Changes

Please provide a brief description of the changes here.

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

@lalitb lalitb requested a review from a team as a code owner July 8, 2024 18:23
@lalitb lalitb marked this pull request as draft July 8, 2024 18:24
@lalitb
Copy link
Member Author

lalitb commented Jul 8, 2024

Moving to draft - Even though AnyValue benchmarks shows improvement, the similar improvement is not reflected in tracing-appender benchmark, possibly for different reason. Looking into that.

@lalitb
Copy link
Member Author

lalitb commented Jul 8, 2024

AnyValue benchmark results:

Benchmark PR Time (ns) Main Time (ns)
CreateOTelValueStaticString 3.7731 3.7642
CreateOTelAnyValueStaticString 4.4106 34.740
CreateOTelValueString 15.083 15.393
CreateOTelAnyValueString 16.076 41.257
CreateOTelValueInt 3.1472 3.1382
CreateOTelAnyValueInt 4.1100 33.097

@lalitb
Copy link
Member Author

lalitb commented Jul 9, 2024

And the LogRecord benchmark. The benchmark for box'ed complex types has gone up slightly as expected (eg for simple-log-with-bytes/no-context , simple-log-with-map-any-value), there is visible improvement for simple types, though not to the scale of AnyValue benchmarks as in above comment.

Benchmark PR Branch Time (ns) Main Branch Time (ns)
simple-log/no-context 123.56 141.61
simple-log/with-context 123.84 140.62
simple-log-with-int/no-context 142.48 156.29
simple-log-with-int/with-context 143.36 155.16
simple-log-with-double/no-context 140.69 155.43
simple-log-with-double/with-context 147.05 153.54
simple-log-with-string/no-context 142.76 156.71
simple-log-with-string/with-context 143.79 154.11
simple-log-with-bool/no-context 144.85 161.52
simple-log-with-bool/with-context 144.18 160.25
simple-log-with-bytes/no-context 165.61 171.69
simple-log-with-bytes/with-context 172.59 173.45
simple-log-with-a-lot-of-bytes/no-context 168.16 175.58
simple-log-with-a-lot-of-bytes/with-context 170.43 174.53
simple-log-with-vec-any-value/no-context 204.47 219.25
simple-log-with-vec-any-value/with-context 207.93 218.56
simple-log-with-inner-vec-any-value/no-context 273.05 313.19
simple-log-with-inner-vec-any-value/with-context 273.08 287.55
simple-log-with-map-any-value/no-context 217.71 223.04
simple-log-with-map-any-value/with-context 219.62 223.06
simple-log-with-inner-map-any-value/no-context 300.22 298.58
simple-log-with-inner-map-any-value/with-context 301.72 300.53
long-log/no-context 124.05 141.42
long-log/with-context 123.79 140.95
full-log/no-context 95.383 116.95
full-log/with-context 111.75 125.99
full-log-with-4-attributes/no-context 200.20 179.25
full-log-with-4-attributes/with-context 202.43 176.71
full-log-with-9-attributes/no-context 338.03 305.05
full-log-with-9-attributes/with-context 337.06 280.23
full-log-with-attributes/no-context 430.26 419.97
full-log-with-attributes/with-context 428.65 413.89

@lalitb
Copy link
Member Author

lalitb commented Jul 9, 2024

Updating benchmark with LogRecord creation for 4 attributes:

Benchmark Main Repo (ns) PR (box'ed) (ns) PR (box'ed + smallVec) (ns)
full-log-with-4-attributes/no-context 165.94 - 166.51 159.96 - 160.40 110.21 - 110.36
full-log-with-4-attributes/with-context 186.79 - 187.43 176.67 - 176.97 133.45 - 133.91

@utpilla
Copy link
Contributor

utpilla commented Jul 9, 2024

Updating benchmark with LogRecord creation for 4 attributes:

Benchmark Main Repo (ns) PR (box'ed) (ns) PR (box'ed + smallVec) (ns)
full-log-with-4-attributes/no-context 165.94 - 166.51 159.96 - 160.40 110.21 - 110.36
full-log-with-4-attributes/with-context 186.79 - 187.43 176.67 - 176.97 133.45 - 133.91

@lalitb I think we need to black_box the static string values provided in the log_record.add_attribute method to see the desired perf difference.

log_benchmark_group(c, "full-log-with-4-attributes", |logger| {
        let mut log_record = logger.create_log_record();
        ...
        log_record.add_attribute("name", black_box("my-event-name"));
        log_record.add_attribute("event.id", black_box(20));
        log_record.add_attribute("user.name", black_box("otel"));
        log_record.add_attribute("user.email", black_box("otel@opentelemetry.io"));
        logger.emit(log_record);
    });

I think the huge perf difference that shows up for simply creating AnyValue for static strings showed up because you wrapped the AnyValue creating with a black_box. I believe if you don't make any changes to the enum and run the create values from static string benchmarks without black_box, you would get comparable results already.

c.bench_function("CreateOTelAnyValueStaticStr", |b| {
        b.iter(|| {
            let _v = black_box(AnyValue::String("value1".into()));
        });
    });

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.

Performance Degradation with AnyValue Enum
2 participants