Skip to content

refactor(cache): optimize concurrency with RWMutex for cache operations #6911

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

flc1125
Copy link
Member

@flc1125 flc1125 commented Jun 17, 2025

Although it is an optimization, whether this optimization is worth doing requires consideration.

package main

import "go.opentelemetry.io/otel"

var meter = otel.Meter("xxx")

func main() {
	meter.Float64Counter("xxxx")
}

In most cases, examples like this show that otel.Meter is typically defined once and not called multiple times. This implies that the cache hit rate itself is extremely low. Consequently, the performance overhead between RWMutex and Mutex calls is almost negligible.

If this scenario holds true, the current PR can be ignored.

Copy link

codecov bot commented Jun 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@be4b9e7). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff           @@
##             main   #6911   +/-   ##
======================================
  Coverage        ?   82.9%           
======================================
  Files           ?     261           
  Lines           ?   24264           
  Branches        ?       0           
======================================
  Hits            ?   20129           
  Misses          ?    3758           
  Partials        ?     377           
Files with missing lines Coverage Δ
sdk/metric/cache.go 100.0% <100.0%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MrAlias
Copy link
Contributor

MrAlias commented Jun 17, 2025

Please include comprehensive evidence in the form of benchmarks and/or profile data to support this change.

This has been evaluated in development and determined to be less performant in the common use-cases. Direct evidence is required for these changes to be considered.

@pellared
Copy link
Member

pellared commented Jun 17, 2025

Isn't RWMutex having a bigger memory footprint?

Are there any benchmarks that proves that it is an optimization?

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.

3 participants