-
Notifications
You must be signed in to change notification settings - Fork 10
[WIP] refactor: enhance put/get string performance #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
str 1k const str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234'; |
|
@dead-horse 看看 |
|
性能提升这么多 |
lib/byte.js
Outdated
| return this; | ||
| }; | ||
|
|
||
| ByteBuffer.prototype.putUTFString = function (str) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释写一下?是utf8?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
什么时候用fast?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
测试发现,当 length 小于 24 的时候 getRawStringByStringLength 是最快的,但是长字符串 getRawStringFast 还是有优势的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- hessian 里面 readType 的时候不可能出现 unicode 字符,所以直接用 getUTF8String
- 用 getRawStringFast 替代 getRawStringByStringLength
- 当 length 小于 24 时(测试结果),降级为 getRawStringByStringLength
- 当探测到 unicode 字符,则马上降级为 getRawStringByStringLength,因为认为一旦出现 unicode,一直出现 unicode 的几率比较高
- 其余用新的逻辑
ad1a02b to
00d094d
Compare
00d094d to
db17a71
Compare
|
我找一个实际的类来测一下 |
|
实际测试效果不佳。。。 |
|
大部分是 小于 20 的 str |
|
搞郁闷了。。。 |





No description provided.