[WIP] refactor: enhance put/get string performance#31
Open
[WIP] refactor: enhance put/get string performance#31
Conversation
Member
Author
|
str 1k const str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234'; |
Member
|
@dead-horse 看看 |
Member
|
性能提升这么多 |
fengmk2
reviewed
Dec 19, 2017
lib/byte.js
Outdated
| return this; | ||
| }; | ||
|
|
||
| ByteBuffer.prototype.putUTFString = function (str) { |
| return this._bytes.toString('utf8', start, this._offset); | ||
| }; | ||
|
|
||
| ByteBuffer.prototype.getRawStringFast = function (length) { |
Member
Author
There was a problem hiding this comment.
测试发现,当 length 小于 24 的时候 getRawStringByStringLength 是最快的,但是长字符串 getRawStringFast 还是有优势的
Member
Author
There was a problem hiding this comment.
- hessian 里面 readType 的时候不可能出现 unicode 字符,所以直接用 getUTF8String
- 用 getRawStringFast 替代 getRawStringByStringLength
- 当 length 小于 24 时(测试结果),降级为 getRawStringByStringLength
- 当探测到 unicode 字符,则马上降级为 getRawStringByStringLength,因为认为一旦出现 unicode,一直出现 unicode 的几率比较高
- 其余用新的逻辑
ad1a02b to
00d094d
Compare
Member
Author
Member
Author
Member
Author
Member
Author
00d094d to
db17a71
Compare
Member
Author
|
我找一个实际的类来测一下 |
Member
Author
|
实际测试效果不佳。。。 |
Member
Author
|
大部分是 小于 20 的 str |
Member
Author
|
搞郁闷了。。。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.





No description provided.