Skip to content

Conversation

@dyolcekaj
Copy link
Contributor

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

To align experimentation across teams and deployments, we've wrapped your SDK in a library that we distribute across the org. This library abstracts away and standardizes most attributes that anyone would want to run an experiment against, and in doing so adds many attributes by default to each ldcontext.Context for evaluations.

When profiling a few deployments for unrelated reasons, we noted that allocations in *ValueMapBuilder.Set(...) were usually at least visible in profiling although not egregiously so. Because we know the number of attributes we can define a capacity to pre-allocate and this would be a moderate reduction in allocations across a majority of our deployments.

Describe the solution you've provided

Add a new constructor ldcontext.NewBuilderWithCapacity(key string, capacity int) that utilizes ldvalue.ValueMapBuilderWithCapacity(capacity int).

Describe alternatives you've considered

I got cute with functional options for a second but I reeled it in.

Additional context

Benchmarks

✗ go test -run='^$' -bench=BenchmarkBuildWithCustomAttributes -benchmem
goos: darwin
goarch: amd64
pkg: github.com/launchdarkly/go-sdk-common/v3/ldcontext
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkBuildWithCustomAttributes/with_2_attributes-16         	 4110615	       279.1 ns/op	    1072 B/op	       2 allocs/op
BenchmarkBuildWithCustomAttributes/with_10_attributes-16        	 1000000	      1040 ns/op	    3141 B/op	       3 allocs/op
BenchmarkBuildWithCustomAttributes/with_50_attributes-16        	  193011	      5905 ns/op	   17782 B/op	       7 allocs/op
BenchmarkBuildWithCustomAttributesWithCapacity/with_2_attributes-16         	 4233372	       277.0 ns/op	    1072 B/op	       2 allocs/op
BenchmarkBuildWithCustomAttributesWithCapacity/with_10_attributes-16        	 1565258	       748.0 ns/op	    2117 B/op	       2 allocs/op
BenchmarkBuildWithCustomAttributesWithCapacity/with_50_attributes-16        	  346684	      3492 ns/op	    9600 B/op	       3 allocs/op
PASS
ok  	github.com/launchdarkly/go-sdk-common/v3/ldcontext	9.636s
➜

@dyolcekaj dyolcekaj requested a review from a team as a code owner July 23, 2025 03:35
Copy link
Member

@keelerm84 keelerm84 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for your contribution!

@keelerm84 keelerm84 merged commit 8c65d90 into launchdarkly:v3 Jul 25, 2025
12 checks passed
@github-actions github-actions bot mentioned this pull request Jul 8, 2025
keelerm84 pushed a commit that referenced this pull request Jul 25, 2025
🤖 I have created a release *beep* *boop*
---


##
[3.4.0](v3.3.0...v3.4.0)
(2025-07-25)


### Features

* Add ldcontext.NewBuilderWithCapacity constructor
([#40](#40))
([8c65d90](8c65d90))


### Bug Fixes

* Bump minimum go version to 1.24
([3a5523a](3a5523a))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@keelerm84
Copy link
Member

This has been released in v3.4.0. The LD SDK was updated to also use this latest version as of v7.13.1

Thanks again!

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.

2 participants