wu-sheng opened a new pull request, #13750:
URL: https://github.com/apache/skywalking/pull/13750

   ### Improve the performance of MAL v2 closure dispatch in MALClosureCodegen
   
   - [x] Add a benchmark for the improvement, refer to [the existing 
ones](https://github.com/apache/skywalking/blob/master/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/LinkedArrayBenchmark.java)
   - [ ] The benchmark result.
   - [ ] Links/URLs to the theory proof or discussion articles/blogs.
   
   **What changed:**
   
   Closure functional interface instances (`TagFunction`, `ForEachFunction`, 
`PropertiesExtractor`, `DecorateFunction`) were previously wired via 
`LambdaMetafactory` after class loading. This required:
   1. A static helper method on the main class (e.g. `_tag_apply(Map)`)
   2. A companion class delegating back to that method (e.g. 
`MainClass$_tag.apply() → MainClass._tag_apply()`)
   3. Reflective method lookup at runtime via `MethodHandles.lookup()`
   
   Now each companion class directly implements the functional interface with 
the **closure body inlined** in the SAM method — no reflection, no 
LambdaMetafactory, no indirection:
   
   ```java
   // Before: two-level indirection
   class MainClass { static Map _tag_apply(Map tags) { /* body */ } }
   class MainClass$_tag { Object apply(Object raw) { return 
MainClass._tag_apply((Map)raw); } }
   
   // After: body lives directly in companion
   class MainClass$_tag implements TagFunction {
       public Object apply(Object _raw) {
           Map tags = (Map) _raw;
           /* body */
           return tags;
       }
   }
   ```
   
   **Key fix included:** `TagFunction` and `PropertiesExtractor` extend 
`Function<Map,Map>` whose erased SAM is `apply(Object)Object`, not 
`apply(Map)Map`. The companion SAM method uses `Object` parameter/return with a 
cast to avoid `AbstractMethodError` at runtime.
   
   **Removed dead code:** `addClosureMethod()`, 
`addStaticLocalVariableTable()`, the `isStatic` parameter on 
`addLocalVariableTable()`, and `generateCompanionMethod()`.
   
   - [ ] If this pull request closes/resolves/fixes an existing issue, replace 
the issue number. Closes #<issue number>.
   - [ ] Update the [`CHANGES` 
log](https://github.com/apache/skywalking/blob/master/docs/en/changes/changes.md).


-- 
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