You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by "lujiajing1126 (via GitHub)" <gi...@apache.org> on 2023/11/01 07:56:20 UTC
Re: [PR] Optimize bytebuddy type description performance [skywalking-java]
lujiajing1126 commented on code in PR #637:
URL: https://github.com/apache/skywalking-java/pull/637#discussion_r1378491612
##########
apm-sniffer/bytebuddy-patch/src/main/java/net/bytebuddy/agent/builder/SWDescriptionStrategy.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package net.bytebuddy.agent.builder;
+
+import net.bytebuddy.agent.builder.AgentBuilder.PoolStrategy.WithTypePoolCache.Simple;
+import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.pool.TypePool;
+import net.bytebuddy.utility.JavaModule;
+import net.bytebuddy.utility.nullability.MaybeNull;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * A DescriptionStrategy with interoperable cache provider.
+ */
+public class SWDescriptionStrategy implements AgentBuilder.DescriptionStrategy {
+
+ private Simple typePoolCache = new Simple(new ConcurrentHashMap<>());
+
+ private AgentBuilder.DescriptionStrategy delegate = AgentBuilder.DescriptionStrategy.Default.HYBRID;
+
+ @Override
+ public boolean isLoadedFirst() {
+ return true;
+ }
+
+ @Override
+ public TypeDescription apply(String name,
+ @MaybeNull Class<?> type,
+ TypePool typePool,
+ AgentBuilder.CircularityLock circularityLock,
+ @MaybeNull ClassLoader classLoader,
+ @MaybeNull JavaModule module) {
+ // use cache first
+ TypePool.CacheProvider cacheProvider = getCacheProvider(classLoader);
+ TypePool.Resolution resolution = cacheProvider.find(name);
+ if (resolution != null && resolution.isResolved()) {
+ return resolution.resolve();
+ }
+ // do as AgentBuilder.DescriptionStrategy.Default.HYBRID
+ return delegate.apply(name, type, typePool, circularityLock, classLoader, module);
Review Comment:
> @lujiajing1126 Can you provide the memory analysis data of these two caching ways?
I will check this issue soon
--
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: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org