Skip to content
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

Imp: cache in reflection #179

Merged
merged 15 commits into from
Apr 20, 2020
Merged

Imp: cache in reflection #179

merged 15 commits into from
Apr 20, 2020

Conversation

micln
Copy link
Contributor

@micln micln commented Apr 11, 2020

What this PR does:

Which issue(s) this PR fixes:

Fixes #169

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@micln
Copy link
Contributor Author

micln commented Apr 11, 2020

why cache in findField ?

image

$ go test -benchmem -run=^$ github.com/apache/dubbo-go-hessian2 -bench "^(BenchmarkDecode)$" -vet=off -v

before

BenchmarkDecode-8   	   61917	     18027 ns/op	    7448 B/op	     224 allocs/op

after

BenchmarkDecode-8   	   81508	     12387 ns/op	    7224 B/op	     126 allocs/op

go.mod Outdated Show resolved Hide resolved
@wongoo
Copy link
Contributor

wongoo commented Apr 11, 2020

great job

object.go Show resolved Hide resolved
object.go Show resolved Hide resolved
@micln micln changed the title cache in decode reflection cache in reflection Apr 11, 2020
@micln micln marked this pull request as draft April 11, 2020 07:17
pojo.go Show resolved Hide resolved
@micln
Copy link
Contributor Author

micln commented Apr 12, 2020

go test doesn't work stable, this is a result seems average

As a whole, hessian encode/decode is performance 85% of json.Marshal/Unmarshal in cpu profiler now.

$ go test -benchmem -run=^$ github.com/apache/dubbo-go-hessian2 -bench "^B" -vet=off -v -count=5
goos: darwin
goarch: amd64
pkg: github.com/apache/dubbo-go-hessian2
BenchmarkJsonEncode
BenchmarkJsonEncode-8   	  249114	      4719 ns/op	     832 B/op	      15 allocs/op
BenchmarkJsonEncode-8   	  252224	      4862 ns/op	     832 B/op	      15 allocs/op
BenchmarkJsonEncode-8   	  240582	      4739 ns/op	     832 B/op	      15 allocs/op
BenchmarkJsonEncode-8   	  213283	      4784 ns/op	     832 B/op	      15 allocs/op
BenchmarkJsonEncode-8   	  227101	      4665 ns/op	     832 B/op	      15 allocs/op
BenchmarkEncode
BenchmarkEncode-8       	  182184	      5615 ns/op	    1771 B/op	      51 allocs/op
BenchmarkEncode-8       	  183007	      5565 ns/op	    1771 B/op	      51 allocs/op
BenchmarkEncode-8       	  218664	      5593 ns/op	    1771 B/op	      51 allocs/op
BenchmarkEncode-8       	  214704	      5886 ns/op	    1770 B/op	      51 allocs/op
BenchmarkEncode-8       	  181861	      5605 ns/op	    1770 B/op	      51 allocs/op
BenchmarkJsonDecode
BenchmarkJsonDecode-8   	  123667	      8412 ns/op	    1776 B/op	      51 allocs/op
BenchmarkJsonDecode-8   	  122796	      8497 ns/op	    1776 B/op	      51 allocs/op
BenchmarkJsonDecode-8   	  132103	      8471 ns/op	    1776 B/op	      51 allocs/op
BenchmarkJsonDecode-8   	  130687	      8492 ns/op	    1776 B/op	      51 allocs/op
BenchmarkJsonDecode-8   	  127668	      8476 ns/op	    1776 B/op	      51 allocs/op
BenchmarkDecode
BenchmarkDecode-8       	  107775	     10092 ns/op	    6424 B/op	      98 allocs/op
BenchmarkDecode-8       	  110996	      9950 ns/op	    6424 B/op	      98 allocs/op
BenchmarkDecode-8       	  111036	     10760 ns/op	    6424 B/op	      98 allocs/op
BenchmarkDecode-8       	  113151	     10063 ns/op	    6424 B/op	      98 allocs/op
BenchmarkDecode-8       	  109197	     10002 ns/op	    6424 B/op	      98 allocs/op
PASS
ok  	github.com/apache/dubbo-go-hessian2	28.680s

@micln micln marked this pull request as ready for review April 12, 2020 12:31
object.go Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Apr 12, 2020

Codecov Report

Merging #179 into master will increase coverage by 0.15%.
The diff coverage is 87.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #179      +/-   ##
==========================================
+ Coverage   67.42%   67.58%   +0.15%     
==========================================
  Files          22       22              
  Lines        2671     2690      +19     
==========================================
+ Hits         1801     1818      +17     
  Misses        666      666              
- Partials      204      206       +2     
Impacted Files Coverage Δ
object.go 65.84% <86.84%> (+1.23%) ⬆️
pojo.go 60.54% <100.00%> (+0.43%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c4e7f35...5f616cd. Read the comment docs.

@micln micln requested review from wongoo and AlexStocks April 12, 2020 14:03
Copy link
Contributor

@wongoo wongoo left a comment

Choose a reason for hiding this comment

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

LGTM

object.go Outdated Show resolved Hide resolved
object_test.go Show resolved Hide resolved
object.go Outdated Show resolved Hide resolved
object.go Show resolved Hide resolved
@micln
Copy link
Contributor Author

micln commented Apr 18, 2020

@AlexStocks @gaoxinge any problem ?

@gaoxinge
Copy link
Contributor

@micln Good job. LGTM.

@wongoo
Copy link
Contributor

wongoo commented Apr 18, 2020

@ALL pls resolve conversations if already resolved, so that make sure it can be merged.

@micln
Copy link
Contributor Author

micln commented Apr 19, 2020

@ALL pls resolve conversations if already resolved, so that make sure it can be merged.

done

object.go Outdated Show resolved Hide resolved
@AlexStocks
Copy link
Contributor

LGTM

@AlexStocks AlexStocks changed the title cache in reflection Imp: cache in reflection Apr 19, 2020
object.go Outdated Show resolved Hide resolved
Copy link
Contributor

@gaoxinge gaoxinge left a comment

Choose a reason for hiding this comment

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

LGTM.

@wongoo wongoo merged commit bb036e6 into apache:master Apr 20, 2020
pantianying added a commit to pantianying/dubbo-go-hessian2 that referenced this pull request Apr 21, 2020
wongoo added a commit that referenced this pull request Jun 15, 2020
* add license checker (#175)

* add release note for v1.5.0 (#178)

Co-authored-by: Xin.Zh <dragoncharlie@foxmail.com>

* Imp: cache in reflection (#179)

* benchmark result

* use cache in findField

* encode benchmark

* call field() once

* remove version

* fix import sync

* cache in registerPOJO

* add json bench result

* prune unneccessary rtype.Field(index)

* cache comment

* rename cache

* switch to if

* remove return value name

* findFieldWithCache

* remove if check when fieldStruct is nil

Co-authored-by: 望哥 <gelnyang@163.com>

* update dependency

* rename serialize arg name

* Create .asf.yaml

* 优化hessian解码string性能,提升54%

* optimize code.

* optimize code.

* fix code review.

* optimize codes.

* optimize cods.

* optimize code.

* update license

* go.sum

* ci go version

* testify -> 1.4.0

* testcase

* travis.yml

* decode value before reflect find

* setvalue

* decode nilPtr to nilPtr

* fix get attachment lost nil key

* manually import package

* add ToMapStringString unit test

* rename test function name with issue

* setmap

* support for decode emoji.

* refactor code

* add unit test.

* add unit tests.

* refactor tests.

* Update travis/main.sh (#200)

- Remove duplicate key 'webhooks'
- Key 'matrix' is an alias for `jobs`, using `jobs`
- Specify the os and dist explicitly

* Mod: modify

* Code format (#199)

* .gitignore

* code clean

* code clean

* remove length check

* Fix: comments

* Fix: format package

* Fix #181: float32 accuracy issue (#196)

* Fix #181: float32 accuracy issue

* Fix go fmt failure

* Add the unit test case for Issue181

* Add encFloat32 in double.go to encode float32 type

- Call encFloat32 to encode float32 while encoding
- Add unit test case to test float32 encoding

* Improve encFloat32 of double.go

* Fix git fmt failure

* add release note for v1.6.0 (#202)

* add release note for v1.5.1

* add release note for v1.5.1

* add notice

* update notice

* =fix release note for v1.6.0

Co-authored-by: Joe Zou <joezou@apache.org>
Co-authored-by: Xin.Zh <dragoncharlie@foxmail.com>
Co-authored-by: huiren <zhrlnt@gmail.com>
Co-authored-by: Huang YunKun <htynkn@gmail.com>
Co-authored-by: zonghaishang <yiji@apache.org>
Co-authored-by: fangyincheng <fangyc666@gmail.com>
Co-authored-by: champly <champly@outlook.com>
Co-authored-by: wilson chen <willson.chenwx@gmail.com>
Co-authored-by: fangyincheng <fangyincheng@sina.com>
Co-authored-by: gaoxinge <gaoxx5@gmail.com>
wongoo added a commit that referenced this pull request Jun 23, 2020
* add license checker (#175)

* add release note for v1.5.0 (#178)

Co-authored-by: Xin.Zh <dragoncharlie@foxmail.com>

* Imp: cache in reflection (#179)

* benchmark result

* use cache in findField

* encode benchmark

* call field() once

* remove version

* fix import sync

* cache in registerPOJO

* add json bench result

* prune unneccessary rtype.Field(index)

* cache comment

* rename cache

* switch to if

* remove return value name

* findFieldWithCache

* remove if check when fieldStruct is nil

Co-authored-by: 望哥 <gelnyang@163.com>

* update dependency

* rename serialize arg name

* Create .asf.yaml

* 优化hessian解码string性能,提升54%

* optimize code.

* optimize code.

* fix code review.

* optimize codes.

* optimize cods.

* optimize code.

* update license

* go.sum

* ci go version

* testify -> 1.4.0

* testcase

* travis.yml

* decode value before reflect find

* setvalue

* decode nilPtr to nilPtr

* fix get attachment lost nil key

* manually import package

* add ToMapStringString unit test

* rename test function name with issue

* setmap

* support for decode emoji.

* refactor code

* add unit test.

* add unit tests.

* refactor tests.

* Update travis/main.sh (#200)

- Remove duplicate key 'webhooks'
- Key 'matrix' is an alias for `jobs`, using `jobs`
- Specify the os and dist explicitly

* Mod: modify

* Code format (#199)

* .gitignore

* code clean

* code clean

* remove length check

* Fix: comments

* Fix: format package

* Fix #181: float32 accuracy issue (#196)

* Fix #181: float32 accuracy issue

* Fix go fmt failure

* Add the unit test case for Issue181

* Add encFloat32 in double.go to encode float32 type

- Call encFloat32 to encode float32 while encoding
- Add unit test case to test float32 encoding

* Improve encFloat32 of double.go

* Fix git fmt failure

* add release note for v1.6.0 (#202)

* add release note for v1.5.1

* add release note for v1.5.1

* add notice

* update notice

* =fix release note for v1.6.0

* Fix: eunm encode in request get error (#203)

* fix bug: eunm encode in request get error

* fix mod

* add ut

* remove go.mod 1.13 to fix the ci

Co-authored-by: Joe Zou <joezou@apache.org>
Co-authored-by: Xin.Zh <dragoncharlie@foxmail.com>
Co-authored-by: huiren <zhrlnt@gmail.com>
Co-authored-by: Huang YunKun <htynkn@gmail.com>
Co-authored-by: zonghaishang <yiji@apache.org>
Co-authored-by: fangyincheng <fangyc666@gmail.com>
Co-authored-by: champly <champly@outlook.com>
Co-authored-by: wilson chen <willson.chenwx@gmail.com>
Co-authored-by: fangyincheng <fangyincheng@sina.com>
Co-authored-by: gaoxinge <gaoxx5@gmail.com>
Co-authored-by: panty <pantianying@gmail.com>
zhaoyunxing92 pushed a commit that referenced this pull request Sep 4, 2021
* benchmark result

* use cache in findField

* encode benchmark

* call field() once

* remove version

* fix import sync

* cache in registerPOJO

* add json bench result

* prune unneccessary rtype.Field(index)

* cache comment

* rename cache

* switch to if

* remove return value name

* findFieldWithCache

* remove if check when fieldStruct is nil

Co-authored-by: 望哥 <gelnyang@163.com>
zhaoyunxing92 pushed a commit that referenced this pull request Sep 4, 2021
* add license checker (#175)

* add release note for v1.5.0 (#178)

Co-authored-by: Xin.Zh <dragoncharlie@foxmail.com>

* Imp: cache in reflection (#179)

* benchmark result

* use cache in findField

* encode benchmark

* call field() once

* remove version

* fix import sync

* cache in registerPOJO

* add json bench result

* prune unneccessary rtype.Field(index)

* cache comment

* rename cache

* switch to if

* remove return value name

* findFieldWithCache

* remove if check when fieldStruct is nil

Co-authored-by: 望哥 <gelnyang@163.com>

* update dependency

* rename serialize arg name

* Create .asf.yaml

* 优化hessian解码string性能,提升54%

* optimize code.

* optimize code.

* fix code review.

* optimize codes.

* optimize cods.

* optimize code.

* update license

* go.sum

* ci go version

* testify -> 1.4.0

* testcase

* travis.yml

* decode value before reflect find

* setvalue

* decode nilPtr to nilPtr

* fix get attachment lost nil key

* manually import package

* add ToMapStringString unit test

* rename test function name with issue

* setmap

* support for decode emoji.

* refactor code

* add unit test.

* add unit tests.

* refactor tests.

* Update travis/main.sh (#200)

- Remove duplicate key 'webhooks'
- Key 'matrix' is an alias for `jobs`, using `jobs`
- Specify the os and dist explicitly

* Mod: modify

* Code format (#199)

* .gitignore

* code clean

* code clean

* remove length check

* Fix: comments

* Fix: format package

* Fix #181: float32 accuracy issue (#196)

* Fix #181: float32 accuracy issue

* Fix go fmt failure

* Add the unit test case for Issue181

* Add encFloat32 in double.go to encode float32 type

- Call encFloat32 to encode float32 while encoding
- Add unit test case to test float32 encoding

* Improve encFloat32 of double.go

* Fix git fmt failure

* add release note for v1.6.0 (#202)

* add release note for v1.5.1

* add release note for v1.5.1

* add notice

* update notice

* =fix release note for v1.6.0

Co-authored-by: Joe Zou <joezou@apache.org>
Co-authored-by: Xin.Zh <dragoncharlie@foxmail.com>
Co-authored-by: huiren <zhrlnt@gmail.com>
Co-authored-by: Huang YunKun <htynkn@gmail.com>
Co-authored-by: zonghaishang <yiji@apache.org>
Co-authored-by: fangyincheng <fangyc666@gmail.com>
Co-authored-by: champly <champly@outlook.com>
Co-authored-by: wilson chen <willson.chenwx@gmail.com>
Co-authored-by: fangyincheng <fangyincheng@sina.com>
Co-authored-by: gaoxinge <gaoxx5@gmail.com>
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.

Use go reflection in JIT way
5 participants