blackdrag commented on PR #3260: URL: https://github.com/apache/groovy/pull/3260#issuecomment-6834554092
There are two aspects I would like to see addressed before merging: **1. Verify cache behavior across different classloaders** `DEFAULT_IMPORT_CLASS_AND_PACKAGES_CACHE` is static and shared across compiler instances, whereas class visibility is determined by the classloader used for each compilation. The new partial-cache algorithm appears to account for this by checking higher-precedence packages before accepting a previously discovered lower-precedence package. However, the regression tests currently do not establish that resolution remains independent of compilation history across different classloaders. I suggest adding a test along these lines: - Classloader A can resolve `groovy.util.X`, but not `groovy.lang.X`. - Compile a reference to `X` using A. - Classloader B can resolve `groovy.lang.X`, but not `groovy.util.X`. - Compile a reference to `X` using B. - Compile another reference using A. The expected resolutions are respectively `groovy.util.X`, `groovy.lang.X` and `groovy.util.X`. This would verify that the globally shared cache does not cause one compilation's classloader visibility to influence another compilation's resolution. **2. Make the cache-state invariant explicit** The distinction between complete and partial cache entries currently relies on object identity: ```java known == indexed ``` This works with the current implementation because startup index entries are shared with the cache, while subsequent updates replace cache values rather than modifying them. However, object identity now carries semantic meaning: it determines which resolution algorithm is used. This is an important invariant for anyone modifying this code in the future. I suggest documenting explicitly that startup entries represent the complete index, dynamically discovered entries are only partial information, and cache updates must preserve this distinction. I would also consider a concurrency regression test for simultaneous resolutions of the same name. The replacement-based update strategy using `ConcurrentHashMap.compute` looks appropriate, but the current tests do not exercise concurrent readers and writers. Overall, I agree with the implementation direction. These suggestions are primarily about establishing and preserving the correctness properties on which the optimization depends. -- 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]
