Comments (10)
同一个classloader中运行一定是会缓存的,除非你是不同的classloader或jvm中运行。 另一个jprotobuf有预编译功能, 参见文档 https://github.com/jhunters/jprotobuf 搜索预编译
from jprotobuf.
@jhunters
🎉
刚看错了代码,protobufproxy是有缓存POJO源代码。
做了一下性能检测,发现getResource这里才是问题所在。
待会测试一下maven插件生成POJO的性能再上来反馈。
from jprotobuf.
通过jprotobuf-precompile-plugin生成的代码也有性能问题。生成的代码如下:
public void writeTo(BannerDtoList var1, CodedOutputStream var2) throws IOException {
ByteString var3 = null;
if(!CodedConstant.isNull(var1.version)) {
var3 = ByteString.copyFromUtf8(var1.version);
}
List var4 = null;
if(!CodedConstant.isNull(var1.list)) {
var4 = var1.list;
}
if(var3 != null) {
var2.writeBytes(1, var3);
}
if(var4 != null) {
CodedConstant.writeToList(var2, 2, FieldType.OBJECT, var4);
}
}
出现问题的代码为
CodedConstant.writeToList(var2, 2, FieldType.OBJECT, var4);
主要的性能问题点在于它里面的调用栈是低效的,阻塞的。
com.baidu.bjf.remoting.protobuf.ProtobufProxy#create(java.lang.Class)
com.baidu.bjf.remoting.protobuf.ProtobufProxy#doCreate
long lastModify = ClassHelper.getLastModifyTime(cls);
经过jvirsualvm的监视器查看,瓶颈点在于:
ClassHelper.getLastModifyTime(cls);
要减少ClassHelper.getLastModifyTime(cls);的延迟,可以考虑两点:
1 减少调用频率,30秒检查一次。
2 优化该方法,降低单次调用延迟。
from jprotobuf.
不需要,只需要不要提前获取时间就可以了,就是将它们两个换个位置
// get last modify time long lastModify = ClassHelper.getLastModifyTime(cls);
String uniClsName = cls.getName(); Codec codec = CACHED.get(uniClsName); if (codec != null) { return codec; }
from jprotobuf.
采用运行时加载,多个线程同时调用的时候put/get。ProtobufProxy的Cache时候存在线程安全的问题
from jprotobuf.
fixed at 1.10.4 and 2.0.8
from jprotobuf.
doCreate 方法中
// get last modify time
long lastModify = ClassHelper.getLastModifyTime(cls);
上面这行代码为啥不放在
Class<?> newClass = JDKCompilerHelper.getJdkCompiler().compile(className, code, cls.getClassLoader(), fos, lastModify);
真正需要用到的前面呢?
from jprotobuf.
早已修改,是不是使用的老版本?
from jprotobuf.
maven 库有更新么?? 我用的 2.0.8 版本
from jprotobuf.
刚发布,请更新2.0.9版本
from jprotobuf.
Related Issues (20)
- Avoid create lot of CodedOutputStream instance!
- protobuf-java3.9.0有问题, 需要升级一下.
- 如何自定义 生成proto文件的package 名称?
- protobuf-java 可否打成 shade 包? HOT 2
- ProtobufProxy.create 在高并发的情况下会Block线程 HOT 3
- 父类与子类字段序列化顺序错误 HOT 2
- protobuf-java3.9.2有漏洞提示 HOT 1
- jprotobuf嵌套对象,多文件导出,嵌套对象定义重复 HOT 3
- pojo中类型为short的无法进行创建proto代理 HOT 3
- java.lang.IllegalArgumentException: 无效的源发行版: 1.8
- 这里public的静态变量和set方法冲突
- 预编译插件发生错误 HOT 2
- java21中无法使用预编译,且打成jar包后无法运行 HOT 7
- 预编译插件在复杂对象中可能编译出错 HOT 7
- List<Date>类型字段预编译报错 HOT 2
- 预编译插件,一个实体被多个实体依赖时预编译中断 HOT 5
- java转.proto pojo的注释不会带到生成的.proto中
- 序列化在开发环境可以正常使用,但打成 jar 包运行后,序列化时会报错 HOT 6
- java21,springBoot3.2 打 jar 后使用异常
- 配置outputDirectory参数不生效,没有移动编译后的代码到outputDirectory中
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jprotobuf.