Code Monkey home page Code Monkey logo

node-thrift-protocol's People

Contributors

yanagieiichi avatar yejiayu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-thrift-protocol's Issues

tString concat 改成 alloc + write, 性能提升

今天把原本的各种自定义类型 class 改成 function 后性能并没有显著提升

想到能不能从 buffer 上找突破口

网上翻了点文章加看 buffer js 层面的源码后把

// tString 修改前
if (!(str instanceof Buffer)) str += '';
let sbuf = new Buffer(str, enc);
return Buffer.concat([ new TInt32(sbuf.length), sbuf ]));

// tString 修改后
if (!(str instanceof Buffer)) str += '';

const length = Buffer.byteLength(str, enc);
const buf = Buffer.allocUnsafe(length + 4);
buf.writeInt32BE(length);
if (str instanceof Buffer) {
  str = str.toString();
}

buf.write(str, 4);
return buf;

性能提升了一倍左右, 处理的字符串越多越明显, 具体可以看下 benchmark

https://github.com/yejiayu/node-thrift-protocol/tree/benchmark
npm i && npm run benchmark

如果能把现在代码中的 concat 形式都改了性能应该能得到很大提升? 不过因为结构比较特殊似乎不太好改

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.