Skip to content

[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
gnodet:backport/maven-4.0.x/pr-2495
Jul 18, 2025
Merged

[maven-4.0.x] Expand value interning optimization and add configurable session property (#2495)#10932
gnodet merged 1 commit intoapache:maven-4.0.xfrom
gnodet:backport/maven-4.0.x/pr-2495

Conversation

@gnodet
Copy link
Copy Markdown
Contributor

@gnodet gnodet commented Jul 17, 2025

Backport

This will backport the following commits from master to maven-4.0.x:

Questions ?

Please refer to the Backport tool documentation

…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
@gnodet gnodet merged commit 3ccf3bf into apache:maven-4.0.x Jul 18, 2025
19 checks passed
@github-actions github-actions Bot added this to the 4.0.0 milestone Jul 18, 2025
@gnodet gnodet deleted the backport/maven-4.0.x/pr-2495 branch July 18, 2025 08:20
@gnodet gnodet added the bug Something isn't working label Oct 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant