danielsun1106 edited a comment on issue #1135: GROOVY-8298: Slow Performance Caused by Invoke Dynamic URL: https://github.com/apache/groovy/pull/1135#issuecomment-570811643 Jochen, the main idea can be described as the following code: ```java if (cacheHits(receiverCassName)) { // Try to find the cached MethodHandle // the main logic of `fromCache` MethodHandle mh = lruCache.get(receiverCassName); // find the cached MethodHandle again... return mh.invokeExact(...); } else { // fallback, and put the fallback methodhandle to the inline cache(LRU) for reuse // the main logic of `selectMethod` Selector selector = Selector.getSelector(...); selector.setCallSiteTarget(); MethodHandle mh = selector.handle.asSpreader(...).asType(...); lruCache.put(receiverCassName, mh); // cache the methodhandle return mh.invokeExact(...); } ``` As the inline cache is implemented as LRU cache, and `cacheHits` and `fromCache` are executed in two steps(not atomic), so if `cacheHits` returns `true`(means cached methodhandle found), `fromCache` find the same cached methodhandle from LRU cache again, the result probably is `null` as cached methodhandle may be cleared according to the rule of LRU... I use `ThreadLocal` to avoid the above concurrent issue. Also, we have inline cache for callsite, so `setTarget` can be avoided, which causes the poor performance as the GROOVY-8298 shown.
---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services