Repository navigation
Return read-only JSON flag values with exact integers - #13484
Draft
leoromanovsky wants to merge 3 commits into
Draft
leoromanovsky wants to merge 3 commits into
leoromanovsky wants to merge 3 commits into
Conversation
Each evaluation of a JSON flag converted the whole variant tree to a new OpenFeature Value. The cost grew with the variant size: about 21 us and 83 KB for a 712-node variant. The parser now builds one Value for each JSON object or array variant. Evaluations return that instance. Its structures are MutableStructure over unmodifiable maps and its lists are unmodifiable, so callers cannot change it, and equals is the same as Value.objectToValue. The plain-map form is built once and shared. Integers in JSON variant values now stay Integer or Long instead of Double, so 5 is returned as 5 and integers above 2^53 stay exact. Scalar flags keep Double values.
This comment has been minimized.
This comment has been minimized.
Contributor
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
This was referenced Nov 16, 2026
- Keep Long values only when the loaded OpenFeature SDK supports them. SDK 1.21.0 and older reject a Long with TypeMismatchError, which rejected the whole configuration. - Freeze JSON variants in the parser, and store the frozen tree's plain form as Variant.value. The parsed tree is no longer kept as well. - Make the parser scope follow positions, so a flag keyed "variations" keeps exact integers. - Change nested integers of non-JSON flags back to Double, as before. - Use one number model for JSON fixture defaults and results. - Size maps exactly, and make FrozenValues package-private. - Correct javadoc, and document the read-only values and exact integers. - Add tests for the CDN envelope, the "variations" key, non-JSON flags and integers beyond the long range.
Handle non-JSON flags first in toVariant, use assertNull, and shorten the javadoc. No behavior change.
This branch has not been deployed
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.
What Does This Do
Valuethat is built once when the configuration is parsed. Before this change, each evaluation converted the whole variant tree to a newValue.5is returned as5and not as5.0, and integers up toLong.MAX_VALUEdo not lose precision.Motivation
Customers that use many JSON flags pay a per-evaluation cost that grows with the variant size. Before this change, one evaluation of a JSON variant with about 700 nodes takes about 13 µs and allocates about 57 KB (see Results).
The JSON number handling is also a correctness bug. The parser reads every JSON number as a
double. So integer fields come back asDouble, and integer IDs above 2^53 change value.Changes
ufc/FrozenValues(new package-private class): converts a parsed JSON tree to aValuethat cannot change.FrozenStructure, aMutableStructureover an unmodifiable map. It does not overrideequals,hashCodeorcanEqual, so equality withValue.objectToValuedoes not change.getValuereturns the shared child without a copy.FrozenStructure.asObjectMap()builds the plain-map form once and then shares it. The map and all of its nested maps and lists are unmodifiable.LONG_VALUEStells whether the loaded OpenFeature SDK hasValue(Long). SDK 1.22.0 added it.ufc/Variant: new fieldfrozenValue, and a constructor that takes it. The parser sets it for a JSON flag whose value is an object or an array.UniversalFlagConfigParser:flags.<flag>.variations.<key>.valueare read asIntegerorLong. Larger integers stayDouble, as before. The scope follows positions, so a flag key such as"variations"does not change it.LongstayDouble, as before. Such an SDK rejects aLongvalue withTypeMismatchError, which would reject the whole configuration.toVariant. Its plain form (the sharedasObjectMap()map) replaces the parsed tree asVariant.value, so the parsed containers are not kept as well.Double, also when they are nested in a container, so these flags do not change.FlagEvaluator.resolveVariant: returnsfrozenValueforValuetargets. Other targets usemapValue, as before.README.md: two notes under "Migrating from earlier versions" about read-only values and exact integers.FlagEvaluatorJsonValueTest. It checks that the instance is shared, that the value is equal toValue.objectToValue, that integers are exact (also through theparseJsonApienvelope and for a flag keyed"variations"), that the value cannot change, that array variants work, that condition values and non-JSON flags stayDouble, and that integers beyond the long range stayDouble.CanonicalFixtureTest. The shared fixturetest-json-config-flag.jsonexpects"integer": 1and"float": 1.0. The test normalized the expected integers to doubles, to match the old parser. It now keeps exact integers for the results and the default values of JSON cases.dd-openfeaturetests: 1573 tests, 1567 passed, 6 skipped, 0 failed.{"id":3000000000}parses. Before theLONG_VALUEScheck, the parse threwTypeMismatchError.Results
Local JMH benchmark (not in a repository yet), dd-openfeature 1.69.0 compared with this branch, through the OpenFeature client (
getObjectValue). JMH SampleTime, 2 forks × 5 iterations of 3 s, after 5 warm-up iterations of 2 s. macOS arm64, JDK 17. The two versions ran one after the other for each scenario. These numbers are from the first commit. The second commit does not change the evaluation path. The allocation values are exact. The load average was 5–26 during the run, so the absolute times are higher than on an idle host. The error is ±1–4% of the mean.evalAndReadaddsasStructure().asObjectMap(), which applications often call.mixeduses a realistic mix of all flag types (12% JSON). It shows that the other flag types do not get slower.Retained memory of the JSON variants, measured with JOL (
GraphLayout.totalSize()of allVariant.valueandVariant.frozenValueobjects). The synthetic configuration has 300 JSON flags with 3 variants each. Each variant has 40 scalar fields, a nested object with 10 fields, and an array with 20 strings.asObjectMap()on each variantThe first commit kept the parsed tree next to the frozen tree: 7,228 KB, and 9,323 KB after
asObjectMap().Decisions
frozenValue, so the parsed tree is no longer read. The plain form is the sharedasObjectMap()map, soVariant.valuestays an equal plain tree without a second copy.Longsupport instead of requiring a newer SDK. The provider declares OpenFeature SDK 1.23.0, but Maven can resolve an older SDK that an application declares directly. With an older SDK, large integers stayDouble, as before this change. The check runs once, when the class loads, and only the parser reads it.MutableStructureover an unmodifiable map, notImmutableStructure.ImmutableStructure.getValuedeep-clones on each call, so each read by the application would be a full copy.MutableStructurekeeps the type and theequalsbehavior of today's result.Double(shard ranges, serial IDs, feature values, numeric conditions). Changing only the variant scope keeps that code as it is.IntegerorLong, notBigInteger.Structure.convertValuecannot convert aBigInteger, soasObjectMap()would throw. Integers outside theLongrange stayDouble, as before.Behavior changes
asObjectMap()map now getsUnsupportedOperationException. Before this change, each evaluation returned a new mutable copy.asMap()still returns a newHashMapcopy.aftermakes the evaluation return the default value with theGENERALerror code.asObjectMap(),Value.asObject()andValue.equalssee5(Integer) instead of5.0(Double) for JSON integers. This fixes the bug, but it can change what an application serializes or compares. For example,value.equals(new Value(5.0))is now false.Value.asInteger()on an integer above 2^31-1 now wraps (Long.intValue()). Before, theDoublesaturated.Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issue