eleme / node-thrift-protocol Goto Github PK
View Code? Open in Web Editor NEWAn implementation of thrift-protocol with node.
License: MIT License
An implementation of thrift-protocol with node.
License: MIT License
今天把原本的各种自定义类型 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 形式都改了性能应该能得到很大提升? 不过因为结构比较特殊似乎不太好改
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.