Optimize ClassNameReader.getClassName via direct ASM API#36814
Open
cookie-meringue wants to merge 1 commit into
Open
Optimize ClassNameReader.getClassName via direct ASM API#36814cookie-meringue wants to merge 1 commit into
cookie-meringue wants to merge 1 commit into
Conversation
0e8a5f1 to
d2b655e
Compare
getClassName now calls ClassReader.getClassName() directly instead of routing through the visitor-based getClassInfo. Previously, it allocated a List and a ClassVisitor and decoded super_class and every interface name only to discard all but the first element. The method is on the hot path of every CGLIB proxy class definition, so this change significantly lowers its per-call processing cost. Signed-off-by: cookie-meringue <daehyeon3351@gmail.com>
d2b655e to
6045ec5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change
ClassNameReader.getClassNamenow callsClassReader.getClassName()directly instead of delegating to the visitor-basedgetClassInfo(r)[0].Before
After
Motivation
ClassNameReader.getClassNameis a small utility that extracts the FQCN from class bytecode (e.g.byte[]→"com.example.MyService").It sits on the hot path of every CGLIB proxy class definition.
The previous implementation did all of the following:
ArrayListand aClassVisitor.this_class,super_class, and every interface name.replace('/', '.')andarray.add()on each name.EARLY_EXITand caught it to break out of the visitor.toArray(new String[0]).After all that work, the caller used only
[0]of the result —super_classand the interface names were thrown away.Impact
Per call, the new path:
super_classand every interface name.throw/catchround-trip.JMH measurements
ClassNameReaderBenchmark(5 forks × 5 warmup × 5 measurement)Without additional interfaces — proxy =
extends ProxyTarget implements FactorygetClassInfo(r)[0]r.getClassName().replace('/', '.')With 3 additional interfaces —
Cloneable, Comparable, RunnablegetClassInfo(r)[0]r.getClassName().replace('/', '.')How to run
The new path's time and allocation stay constant regardless of how many interfaces the proxy declares. The legacy path, by contrast, decodes every interface name from the class header and runs the extra
replace/addwork — so the gap widens as the proxy implements more interfaces.