From 1616340470fa1269e8fba93caf48cdc974dcdb8c Mon Sep 17 00:00:00 2001 From: yumos Date: Mon, 17 Mar 2025 23:27:08 +0800 Subject: [PATCH 1/6] Initialize map with `len(keys)` in `NewAllowKeysFilter` and `NewDenyKeysFilter` to avoid rehashing. --- attribute/filter.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/attribute/filter.go b/attribute/filter.go index be9cd922d87..3eeaa5d4426 100644 --- a/attribute/filter.go +++ b/attribute/filter.go @@ -19,7 +19,7 @@ func NewAllowKeysFilter(keys ...Key) Filter { return func(kv KeyValue) bool { return false } } - allowed := make(map[Key]struct{}) + allowed := make(map[Key]struct{}, len(keys)) for _, k := range keys { allowed[k] = struct{}{} } @@ -38,7 +38,7 @@ func NewDenyKeysFilter(keys ...Key) Filter { return func(kv KeyValue) bool { return true } } - forbid := make(map[Key]struct{}) + forbid := make(map[Key]struct{}, len(keys)) for _, k := range keys { forbid[k] = struct{}{} } From 70bbaf0eafc95a2bb8afa22559d47bdd1b27e66f Mon Sep 17 00:00:00 2001 From: yumos Date: Tue, 18 Mar 2025 18:31:57 +0800 Subject: [PATCH 2/6] add a changelog entry. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b80fe0ec96..941862647f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Stop percent encoding header environment variables in `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc` and `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#6392) +### Changed + +- Initialize map with `len(keys)` in `NewAllowKeysFilter` and `NewDenyKeysFilter` to avoid rehashing in `go.opentelemetry.io/otel/attribute`. (#6455) + From b52b421fc1e0e6c699ce29b2b037ffcecdec2467 Mon Sep 17 00:00:00 2001 From: yumos Date: Tue, 18 Mar 2025 20:09:47 +0800 Subject: [PATCH 3/6] update --- CHANGELOG.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4a85592219..6a869480bbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Changed +- Initialize map with `len(keys)` in `NewAllowKeysFilter` and `NewDenyKeysFilter` to avoid rehashing in `go.opentelemetry.io/otel/attribute`. (#6455) - ⚠️ Update `github.com/prometheus/client_golang` to `v1.21.1`, which changes the `NameValidationScheme` to `UTF8Validation`. This allows metrics names to keep original delimiters (e.g. `.`), rather than replacing with underscores. This can be reverted by setting `github.com/prometheus/common/model.NameValidationScheme` to `LegacyValidation` in `github.com/prometheus/common/model`. (#6433) @@ -22,10 +23,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Stop percent encoding header environment variables in `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc` and `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#6392) -### Changed - -- Initialize map with `len(keys)` in `NewAllowKeysFilter` and `NewDenyKeysFilter` to avoid rehashing in `go.opentelemetry.io/otel/attribute`. (#6455) - From 90b3983c1a94c1258a0aac6d6e567dfb47e9df35 Mon Sep 17 00:00:00 2001 From: yumos Date: Tue, 18 Mar 2025 20:14:03 +0800 Subject: [PATCH 4/6] move --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a869480bbf..3d87fc1745e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,10 +14,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Changed -- Initialize map with `len(keys)` in `NewAllowKeysFilter` and `NewDenyKeysFilter` to avoid rehashing in `go.opentelemetry.io/otel/attribute`. (#6455) - ⚠️ Update `github.com/prometheus/client_golang` to `v1.21.1`, which changes the `NameValidationScheme` to `UTF8Validation`. This allows metrics names to keep original delimiters (e.g. `.`), rather than replacing with underscores. This can be reverted by setting `github.com/prometheus/common/model.NameValidationScheme` to `LegacyValidation` in `github.com/prometheus/common/model`. (#6433) +- Initialize map with `len(keys)` in `NewAllowKeysFilter` and `NewDenyKeysFilter` to avoid rehashing in `go.opentelemetry.io/otel/attribute`. (#6455) ### Fixes From 4a0cad156d61d936c51cc039abcdd064660b7ae3 Mon Sep 17 00:00:00 2001 From: yumos Date: Tue, 18 Mar 2025 21:04:51 +0800 Subject: [PATCH 5/6] fix --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d87fc1745e..01ccc4450c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - ⚠️ Update `github.com/prometheus/client_golang` to `v1.21.1`, which changes the `NameValidationScheme` to `UTF8Validation`. This allows metrics names to keep original delimiters (e.g. `.`), rather than replacing with underscores. This can be reverted by setting `github.com/prometheus/common/model.NameValidationScheme` to `LegacyValidation` in `github.com/prometheus/common/model`. (#6433) -- Initialize map with `len(keys)` in `NewAllowKeysFilter` and `NewDenyKeysFilter` to avoid rehashing in `go.opentelemetry.io/otel/attribute`. (#6455) +- Initialize map with `len(keys)` in `NewAllowKeysFilter` and `NewDenyKeysFilter` to avoid necessary allocations in `go.opentelemetry.io/otel/attribute`. (#6455) ### Fixes From 156e535e97433d79c59438eb293f7cc72daf224d Mon Sep 17 00:00:00 2001 From: yumos Date: Tue, 18 Mar 2025 21:47:42 +0800 Subject: [PATCH 6/6] fix --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01ccc4450c5..609c68cfc0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - ⚠️ Update `github.com/prometheus/client_golang` to `v1.21.1`, which changes the `NameValidationScheme` to `UTF8Validation`. This allows metrics names to keep original delimiters (e.g. `.`), rather than replacing with underscores. This can be reverted by setting `github.com/prometheus/common/model.NameValidationScheme` to `LegacyValidation` in `github.com/prometheus/common/model`. (#6433) -- Initialize map with `len(keys)` in `NewAllowKeysFilter` and `NewDenyKeysFilter` to avoid necessary allocations in `go.opentelemetry.io/otel/attribute`. (#6455) +- Initialize map with `len(keys)` in `NewAllowKeysFilter` and `NewDenyKeysFilter` to avoid unnecessary allocations in `go.opentelemetry.io/otel/attribute`. (#6455) ### Fixes