iamhucong opened a new pull request, #38980:
URL: https://github.com/apache/shardingsphere/pull/38980

   ## Problem
   
   `OrderedSPILoader` keeps a singleton-registry cache keyed by a multi-object 
`Collection<?>`.
   
   When callers repeatedly pass transient `RuleConfiguration` or 
`YamlRuleConfiguration` collections, semantically equivalent but newly 
allocated objects can become distinct cache keys. Those keys retain the whole 
rule configuration object graph for the lifetime of the singleton registry. 
Under high-frequency metadata or management SQL workloads, this can lead to 
continuous heap growth, frequent Full GC, and eventually OOM.
   
   ## Changes
   
   - Remove the singleton multi-object collection cache from `OrderedSPILoader`.
   - Keep the single-object fast path, singleton SPI instance reuse, and 
class-based cache.
   - Rebuild the current object-keyed result map from runtime classes for 
multi-object lookups.
   - Add focused tests for multi-object lookups, same-class keys, 
transient/equal keys, comparator ordering, singleton behavior, and prototype 
behavior.
   
   ## Performance impact
   
   This change has a bounded tradeoff.
   
   - `rules.size() == 1`: uses the existing fast path and is effectively 
unchanged.
   - `getServicesByClass(...)`: effectively unchanged.
   - `@SingletonSPI + getServices(..., multi-object collection)`: rebuilds the 
current object-keyed map on each call.
   
   Local JMH results:
   
   - single object fast path: `3.280 -> 3.362 ns/op`
   - byClass multi: `40.127 -> 37.213 ns/op`
   - singleton stable multi-object: `5.831 -> 98.860 ns/op`
   - singleton transient multi-object: `602.661 -> 194.554 ns/op`
   
   For the main SQL path, the affected part is only the SPI lookup during Route 
/ Rewrite / ExecutionPrepare / Merge construction. On databases with multiple 
rules, each affected lookup adds about `93 ns` in the benchmark. SQL parsing, 
route calculation, SQL rewrite generation, execution, result merge logic, 
network I/O, and database I/O are not changed.
   
   ## Verification
   
   - `./mvnw spotless:apply -Pcheck -T1C`
   - `./mvnw checkstyle:check -Pcheck -T1C`
   - `./mvnw -pl infra/spi -DskipITs -Dspotless.skip=true test`
   - `./mvnw -pl infra/spi -Pcheck -DskipTests apache-rat:check`
   - Local before/after JMH verification
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to