You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2020/05/15 04:17:03 UTC

[GitHub] [dubbo-go-hessian2] gaoxinge commented on a change in pull request #188: Perf decode string

gaoxinge commented on a change in pull request #188:
URL: https://github.com/apache/dubbo-go-hessian2/pull/188#discussion_r425556871



##########
File path: string.go
##########
@@ -343,36 +342,137 @@ func (d *Decoder) decString(flag int32) (string, error) {
 						last = true
 					}
 
-					l, err := d.getStringLength(b)
+					charLen, err = d.getStringLength(b)
 					if err != nil {
 						return s, perrors.WithStack(err)
 					}
-					charTotal += l
-					bs := make([]rune, charTotal)
-					copy(bs, runeData)
-					runeData = bs
 
+					if chunkLen < 0 {
+						chunkLen = 0
+					}
+
+					if charLen < 0 {
+						charLen = 0
+					}
+
+					chunkLen += charLen
+
+					remain, cap := len(bytesBuf)-offset, charLen<<2
+					if remain < cap {
+						grow := len(bytesBuf) + cap
+						bs := make([]byte, grow)
+						copy(bs, bytesBuf)
+						bytesBuf = bs
+					}
 				default:
 					return s, perrors.New("expect string tag")
 				}
 			}
 
-			r, charLen, byteLen, err = decodeUcs4Rune(d.reader)
+			if buffed := d.Buffered(); chunkLen > 0 {
+				nread, err := d.next(bytesBuf[offset : offset+chunkLen])

Review comment:
       我的理解:`chunkLen`是表示字符串的长度,不是表示字符串在对应编码下byte的长度。byte的长度应该比`chunkLen`大才对。这样不会有问题么?

##########
File path: decode_test.go
##########
@@ -126,3 +127,16 @@ func testDecodeFrameworkFunc(t *testing.T, method string, expected func(interfac
 	}
 	expected(r)
 }
+
+func BenchmarkDecodeStringOptimized(t *testing.B) {

Review comment:
       Place decode string benchmark to `string_test.go`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org