Skip to content

Conversation

@gxcsoccer
Copy link
Member

No description provided.

@gxcsoccer
Copy link
Member Author

gxcsoccer commented Dec 19, 2017

str 1k

const str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234';

image

@fengmk2
Copy link
Member

fengmk2 commented Dec 19, 2017

@dead-horse 看看

@fengmk2
Copy link
Member

fengmk2 commented Dec 19, 2017

性能提升这么多

lib/byte.js Outdated
return this;
};

ByteBuffer.prototype.putUTFString = function (str) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释写一下?是utf8?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

恩,我改成 UTF8

return this._bytes.toString('utf8', start, this._offset);
};

ByteBuffer.prototype.getRawStringFast = function (length) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

什么时候用fast?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试发现,当 length 小于 24 的时候 getRawStringByStringLength 是最快的,但是长字符串 getRawStringFast 还是有优势的

Copy link
Member Author

@gxcsoccer gxcsoccer Dec 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. hessian 里面 readType 的时候不可能出现 unicode 字符,所以直接用 getUTF8String
  2. 用 getRawStringFast 替代 getRawStringByStringLength
    • 当 length 小于 24 时(测试结果),降级为 getRawStringByStringLength
    • 当探测到 unicode 字符,则马上降级为 getRawStringByStringLength,因为认为一旦出现 unicode,一直出现 unicode 的几率比较高
    • 其余用新的逻辑

@gxcsoccer
Copy link
Member Author

短字符串 getRawStringByStringLength 性能最好

const str = '12345678';

image

@gxcsoccer
Copy link
Member Author

20 左右是一个拐点,getRawStringByStringLength 和 getRawStringFast 性能差不多

const str = '123456789012345678901';

image

@gxcsoccer
Copy link
Member Author

str.length === 50

const str = '12345678901234567890123456789012345678901234567890';

image

@gxcsoccer
Copy link
Member Author

长字符串(1k) getRawStringFast 会有优势

image

@gxcsoccer
Copy link
Member Author

我找一个实际的类来测一下

@gxcsoccer
Copy link
Member Author

实际测试效果不佳。。。

@gxcsoccer gxcsoccer changed the title refactor: enhance put/get string performance [WIP] refactor: enhance put/get string performance Dec 19, 2017
@gxcsoccer
Copy link
Member Author

大部分是 小于 20 的 str

@gxcsoccer
Copy link
Member Author

搞郁闷了。。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants