[maven-4.0.x] Expand value interning optimization and add configurable session property (#2495)#10932
Merged
gnodet merged 1 commit intoapache:maven-4.0.xfrom Jul 18, 2025
Conversation
…erty (apache#2495) This PR expands the value interning optimization in Maven's XML parsing and fixes transformer usage across all XML factories to improve memory efficiency during Maven builds. Expanded the InterningTransformer in DefaultModelBuilder to intern 27 commonly repeated contexts: **Core Maven coordinates:** - groupId, artifactId, version, namespaceUri, packaging **Dependency-related fields:** - scope, type, classifier **Build and plugin-related fields:** - phase, goal, execution **Repository-related fields:** - layout, policy, checksumPolicy, updatePolicy **Common metadata fields:** - modelVersion, name, url, system, distribution, status **SCM fields:** - connection, developerConnection, tag **Common enum-like values:** - id, inherited, optional Added MAVEN_MODEL_BUILDER_INTERNS session property to allow users to customize which XML contexts are interned during POM parsing: - Supports comma-separated list of field names - User properties take precedence over system properties - Falls back to default contexts when property not set - Handles whitespace and empty values gracefully Usage examples: - mvn clean install -Dmaven.modelBuilder.interns="groupId,artifactId,version" - maven.modelBuilder.interns=groupId,artifactId,version,scope,type Fixed all XML factories to properly use the transformer from XmlReaderRequest: - DefaultSettingsXmlFactory - Now uses transformer - DefaultToolchainsXmlFactory - Now uses transformer - DefaultPluginXmlFactory - Now uses transformer - DefaultModelXmlFactory - Already working, verified Added comprehensive test coverage: - InterningTransformerTest.java - Tests interning logic and session property functionality - XmlFactoryTransformerTest.java - Tests transformer usage across all XML factories 1. **Memory Efficiency**: String interning reduces memory usage by ensuring identical string values share the same object reference 2. **Performance**: Faster string comparisons using == instead of .equals() for interned strings 3. **Comprehensive Coverage**: All XML parsing in Maven (POMs, settings, toolchains, plugins) now benefits from interning 4. **Customizable**: Users can tailor interning to their specific use cases 5. **Maven-specific Optimization**: Targets the most commonly repeated values in Maven files - **Backward Compatible**: No breaking changes - optimization is transparent to users - **Automatic Application**: All XML parsing automatically benefits from interning - **Proper Integration**: Transformers are correctly passed through the XML factory chain - **Conservative Approach**: Only interns commonly repeated values to avoid memory overhead - **Configurable**: Users can customize which fields are interned via session properties (cherry picked from commit e5d985c) # Conflicts: # src/site/markdown/configuration.properties
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.
Backport
This will backport the following commits from
mastertomaven-4.0.x:Questions ?
Please refer to the Backport tool documentation