perf: preserve payload maps during ingest cleaning - #3974
Draft
djwhitt wants to merge 2 commits into
Draft
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This is a safer replacement for #3765's
LogEventpayload-cleaning optimization.%{}after a scan is cheaper than deleting every keyThe important difference from #3765 is sparse dirty behavior: rebuilding every map helped clean payloads but regressed representative dirty ones. Copy-on-write maps retain most of the clean-path gain while also improving sparse and list-heavy cases.
Benchmark methodology
Environment: Linux, 6 available cores, Elixir 1.19.5, Erlang/OTP 27.3.4.6, JIT enabled, Benchee parallelism 1.
The first commit (
da3e3ca5) adds the benchmark without changing runtime code. Results compare that benchmark-only baseline with this PR's implementation commit.Mutation-density benchmark
Command, run three times per revision as paired baseline/candidate samples; the table reports the median throughput and memory per scenario:
The pathological all-unsafe map is the only measured memory regression. It renames every key, so copy-on-write creates intermediate maps; it remains 6.7% faster. Pre-scanning that case to select a rebuild was tested and was worse on both throughput and measured allocation.
End-to-end
LogEvent.make/2The existing profiling suites were run twice per revision in baseline→candidate and candidate→baseline order. Results below use each scenario's two-run median, then the geometric mean across scenarios.
The existing edge fixture includes a Cloudflare subtree larger than current production output, so the OTEL/edge suite should be read as allocation stress coverage rather than a production payload-frequency model. The seven-shape suite covers three logs, three traces, and one metric.
Validation
../bin/format --check-formatted lib/logflare/logs/ingest_transformers.ex test/logflare/logs/ingest/ingest_transformer_test.exs bench/log_event_cleaner.exsMIX_ENV=test ../bin/x mix compile --warnings-as-errorsMIX_ENV=test ../bin/x mix credo --strict lib/logflare/logs/ingest_transformers.ex test/logflare/logs/ingest/ingest_transformer_test.exs bench/log_event_cleaner.exsMIX_ENV=test ../bin/test test/logflare/logs/ingest/ingest_transformer_test.exs— 1 property, 36 tests, 0 failures