Skip to content

Commit f518c31

Browse files
committed
fixup: use Collections.unmodifiableMap
Signed-off-by: Todd Baert <[email protected]>
1 parent 5c86f3a commit f518c31

File tree

2 files changed

+49
-48
lines changed

2 files changed

+49
-48
lines changed

benchmark.txt

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -125,49 +125,49 @@ Audit done.
125125

126126
# Run progress: 0.00% complete, ETA 00:00:00
127127
# Fork: 1 of 1
128-
[0.001s][warning][gc,init] Consider setting -Xms equal to -Xmx to avoid resizing hiccups
129-
[0.001s][warning][gc,init] Consider enabling -XX:+AlwaysPreTouch to avoid memory commit hiccups
128+
[0.003s][warning][gc,init] Consider setting -Xms equal to -Xmx to avoid resizing hiccups
129+
[0.003s][warning][gc,init] Consider enabling -XX:+AlwaysPreTouch to avoid memory commit hiccups
130130
Iteration 1: num #instances #bytes class name (module)
131131
-------------------------------------------------------
132-
1: 570958 27405984 java.util.HashMap ([email protected])
133-
2: 355982 10905560 [Ljava.lang.Object; ([email protected])
134-
3: 47720 9713208 [B ([email protected])
135-
4: 260500 4168000 dev.openfeature.sdk.ImmutableStructure
136-
5: 250500 4008000 dev.openfeature.sdk.ImmutableContext
137-
6: 166703 4000872 java.util.ArrayList ([email protected])
138-
7: 100000 4000000 dev.openfeature.sdk.HookContext
139-
8: 100000 4000000 dev.openfeature.sdk.HookContext$HookContextBuilder
140-
9: 108963 3486816 java.util.HashMap$EntryIterator ([email protected])
141-
10: 92789 2969248 java.util.ArrayList$Itr ([email protected])
142-
11: 160056 2560896 java.util.HashMap$EntrySet ([email protected])
143-
12: 50000 2400000 dev.openfeature.sdk.FlagEvaluationDetails$FlagEvaluationDetailsBuilder
144-
13: 140 2038632 [Ljdk.internal.vm.FillerElement; ([email protected])
145-
14: 50000 2000000 dev.openfeature.sdk.FlagEvaluationDetails
146-
15: 50000 2000000 dev.openfeature.sdk.ProviderEvaluation
147-
16: 50002 1600064 java.util.Collections$UnmodifiableMap ([email protected])
148-
17: 100001 1600016 dev.openfeature.sdk.NoOpProvider$$Lambda/0x00007b8b5002fa78
149-
18: 50000 1600000 [Ljava.util.List; ([email protected])
150-
19: 100000 1600000 dev.openfeature.sdk.ImmutableMetadata
151-
20: 100000 1600000 dev.openfeature.sdk.OpenFeatureClient$$Lambda/0x00007b8b50087590
132+
1: 560594 26908512 java.util.HashMap ([email protected])
133+
2: 355983 10905600 [Ljava.lang.Object; ([email protected])
134+
3: 47720 9713248 [B ([email protected])
135+
4: 270056 4320896 java.util.HashMap$EntrySet ([email protected])
136+
5: 250136 4002176 dev.openfeature.sdk.ImmutableStructure
137+
6: 100000 4000000 dev.openfeature.sdk.HookContext
138+
7: 100000 4000000 dev.openfeature.sdk.HookContext$HookContextBuilder
139+
8: 240136 3842176 dev.openfeature.sdk.ImmutableContext
140+
9: 147218 3533232 java.util.ArrayList ([email protected])
141+
10: 142 3416648 [Ljdk.internal.vm.FillerElement; ([email protected])
142+
11: 88243 2823776 java.util.HashMap$EntryIterator ([email protected])
143+
12: 67693 2166176 java.util.ArrayList$Itr ([email protected])
144+
13: 50000 2000000 dev.openfeature.sdk.FlagEvaluationDetails
145+
14: 50000 2000000 dev.openfeature.sdk.ProviderEvaluation
146+
15: 60346 1931072 java.util.Collections$UnmodifiableMap ([email protected])
147+
16: 100001 1600016 dev.openfeature.sdk.NoOpProvider$$Lambda/0x000074791c02fa78
148+
17: 50000 1600000 [Ljava.util.List; ([email protected])
149+
18: 100000 1600000 dev.openfeature.sdk.ImmutableMetadata
150+
19: 100000 1600000 dev.openfeature.sdk.ImmutableMetadata$ImmutableMetadataBuilder
151+
20: 100000 1600000 dev.openfeature.sdk.OpenFeatureClient$$Lambda/0x000074791c087590
152152
21: 50000 1200000 dev.openfeature.sdk.FlagEvaluationOptions
153-
22: 68852 1101632 java.util.Optional ([email protected])
154-
23: 66820 1069120 dev.openfeature.sdk.ImmutableMetadata$ImmutableMetadataBuilder
155-
24: 23186 927440 dev.openfeature.sdk.ProviderEvaluation$ProviderEvaluationBuilder
156-
25: 34250 822000 dev.openfeature.sdk.FlagEvaluationOptions$FlagEvaluationOptionsBuilder
153+
22: 20617 989616 dev.openfeature.sdk.FlagEvaluationDetails$FlagEvaluationDetailsBuilder
154+
23: 60896 974336 java.util.Optional ([email protected])
155+
24: 34775 834600 dev.openfeature.sdk.FlagEvaluationOptions$FlagEvaluationOptionsBuilder
156+
25: 18750 750000 dev.openfeature.sdk.ProviderEvaluation$ProviderEvaluationBuilder
157157
26: 4488 720648 [I ([email protected])
158-
27: 26532 636768 java.lang.String ([email protected])
159-
28: 26292 420672 dev.openfeature.sdk.internal.AutoCloseableReentrantReadWriteLock$$Lambda/0x00007b8b5002eae8
160-
29: 17163 411912 dev.openfeature.sdk.HookSupport$$Lambda/0x00007b8b50081800
158+
27: 27435 658440 dev.openfeature.sdk.HookSupport$$Lambda/0x000074791c081800
159+
28: 26532 636768 java.lang.String ([email protected])
160+
29: 23197 556728 dev.openfeature.sdk.HookSupport$$Lambda/0x000074791c083d78
161161
30: 1461 390008 [J ([email protected])
162-
31: 13411 321864 dev.openfeature.sdk.HookSupport$$Lambda/0x00007b8b50083d78
163-
32: 2354 287992 java.lang.Class ([email protected])
162+
31: 21557 344912 dev.openfeature.sdk.internal.AutoCloseableReentrantReadWriteLock$$Lambda/0x000074791c02eae8
163+
32: 2356 288224 java.lang.Class ([email protected])
164164
33: 4591 257096 jdk.internal.org.objectweb.asm.SymbolTable$Entry ([email protected])
165-
34: 10001 240024 java.lang.Double ([email protected])
166-
35: 8754 210096 java.util.ImmutableCollections$MapN$MapNIterator ([email protected])
165+
34: 10344 248256 java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$1 ([email protected])
166+
35: 10001 240024 java.lang.Double ([email protected])
167167
36: 2502 180144 java.lang.reflect.Field ([email protected])
168-
37: 10000 160000 dev.openfeature.sdk.Value
169-
38: 5996 143904 java.lang.StringBuilder ([email protected])
170-
39: 8754 140064 java.util.ImmutableCollections$MapN$1 ([email protected])
168+
37: 10344 165504 java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet ([email protected])
169+
38: 10000 160000 dev.openfeature.sdk.Value
170+
39: 5996 143904 java.lang.StringBuilder ([email protected])
171171
40: 178 138888 [Ljdk.internal.org.objectweb.asm.SymbolTable$Entry; ([email protected])
172172
41: 3820 122240 java.util.concurrent.ConcurrentHashMap$Node ([email protected])
173173
42: 48 122168 [C ([email protected])
@@ -248,20 +248,20 @@ Iteration 1: num #instances #bytes class name (module)
248248
117: 158 5056 java.lang.invoke.MethodTypeForm ([email protected])
249249
118: 152 4864 java.nio.file.attribute.FileTime ([email protected])
250250
truncated...
251-
Total 3202963 105723696
251+
Total 3237354 105727792
252252

253-
0.141 s/op
254-
+totalAllocatedBytes: 105723696.000 bytes
255-
+totalAllocatedInstances: 3202963.000 instances
253+
0.132 s/op
254+
+totalAllocatedBytes: 105727792.000 bytes
255+
+totalAllocatedInstances: 3237354.000 instances
256256
+totalHeap: 521412608.000 bytes
257257

258258

259259

260260
Secondary result "dev.openfeature.sdk.benchmark.AllocationBenchmark.run:+totalAllocatedBytes":
261-
105723696.000 bytes
261+
105727792.000 bytes
262262

263263
Secondary result "dev.openfeature.sdk.benchmark.AllocationBenchmark.run:+totalAllocatedInstances":
264-
3202963.000 instances
264+
3237354.000 instances
265265

266266
Secondary result "dev.openfeature.sdk.benchmark.AllocationBenchmark.run:+totalHeap":
267267
521412608.000 bytes
@@ -282,13 +282,13 @@ different JVMs are already problematic, the performance difference caused by dif
282282
modes can be very significant. Please make sure you use the consistent Blackhole mode for comparisons.
283283

284284
Benchmark Mode Cnt Score Error Units
285-
AllocationBenchmark.run ss 0.141 s/op
286-
AllocationBenchmark.run:+totalAllocatedBytes ss 105723696.000 bytes
287-
AllocationBenchmark.run:+totalAllocatedInstances ss 3202963.000 instances
285+
AllocationBenchmark.run ss 0.132 s/op
286+
AllocationBenchmark.run:+totalAllocatedBytes ss 105727792.000 bytes
287+
AllocationBenchmark.run:+totalAllocatedInstances ss 3237354.000 instances
288288
AllocationBenchmark.run:+totalHeap ss 521412608.000 bytes
289289
[INFO] ------------------------------------------------------------------------
290290
[INFO] BUILD SUCCESS
291291
[INFO] ------------------------------------------------------------------------
292-
[INFO] Total time: 12.108 s
293-
[INFO] Finished at: 2024-10-22T14:58:27-04:00
292+
[INFO] Total time: 12.076 s
293+
[INFO] Finished at: 2024-10-22T15:08:16-04:00
294294
[INFO] ------------------------------------------------------------------------

src/main/java/dev/openfeature/sdk/AbstractStructure.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.HashMap;
44
import java.util.Map;
5+
import java.util.Collections;
56

67
@SuppressWarnings({ "PMD.BeanMembersShouldSerialize", "checkstyle:MissingJavadocType" })
78
abstract class AbstractStructure implements Structure {
@@ -26,7 +27,7 @@ public boolean isEmpty() {
2627
* @return immutable map
2728
*/
2829
public Map<String, Value> asUnmodifiableMap() {
29-
return Map.copyOf(attributes);
30+
return Collections.unmodifiableMap(attributes);
3031
}
3132

3233
/**

0 commit comments

Comments
 (0)