GithubHelp home page GithubHelp logo

Comments (10)

jhunters avatar jhunters commented on July 20, 2024

同一个classloader中运行一定是会缓存的,除非你是不同的classloader或jvm中运行。 另一个jprotobuf有预编译功能, 参见文档 https://github.com/jhunters/jprotobuf 搜索预编译

from jprotobuf.

zydscut avatar zydscut commented on July 20, 2024

@jhunters
🎉
刚看错了代码,protobufproxy是有缓存POJO源代码。
做了一下性能检测,发现getResource这里才是问题所在。
待会测试一下maven插件生成POJO的性能再上来反馈。
image

from jprotobuf.

zydscut avatar zydscut commented on July 20, 2024

通过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.

yourwafer avatar yourwafer commented on July 20, 2024

不需要,只需要不要提前获取时间就可以了,就是将它们两个换个位置
// 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.

YuiFx avatar YuiFx commented on July 20, 2024

采用运行时加载,多个线程同时调用的时候put/get。ProtobufProxy的Cache时候存在线程安全的问题

from jprotobuf.

xiemalin avatar xiemalin commented on July 20, 2024

fixed at 1.10.4 and 2.0.8

from jprotobuf.

wjm0729 avatar wjm0729 commented on July 20, 2024

doCreate 方法中
// get last modify time
long lastModify = ClassHelper.getLastModifyTime(cls);
上面这行代码为啥不放在
Class<?> newClass = JDKCompilerHelper.getJdkCompiler().compile(className, code, cls.getClassLoader(), fos, lastModify);
真正需要用到的前面呢?

from jprotobuf.

xiemalin avatar xiemalin commented on July 20, 2024

早已修改,是不是使用的老版本?

from jprotobuf.

wjm0729 avatar wjm0729 commented on July 20, 2024

maven 库有更新么?? 我用的 2.0.8 版本

from jprotobuf.

xiemalin avatar xiemalin commented on July 20, 2024

刚发布,请更新2.0.9版本

from jprotobuf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.