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

Reflection cache #155

Merged
merged 4 commits into from
Apr 16, 2021
Merged

Conversation

karljj1
Copy link
Collaborator

@karljj1 karljj1 commented Apr 12, 2021

Calling GetMembers is slow and generates a lot of garbage. This introduces a simple cache so that we only need to do the query once and then any subsequent queries can come from the cache. Its quite simple but gave a nice performance improvement and reduced the garbage by quite a lot for us :)

@codecov
Copy link

codecov bot commented Apr 12, 2021

Codecov Report

Merging #155 (bb4e2df) into main (aa9e428) will increase coverage by 0%.
The diff coverage is 100%.

Impacted file tree graph

@@         Coverage Diff         @@
##           main   #155   +/-   ##
===================================
  Coverage    94%    94%           
===================================
  Files        42     42           
  Lines      1749   1762   +13     
===================================
+ Hits       1651   1664   +13     
  Misses       98     98           
Impacted Files Coverage Δ
src/SmartFormat/Extensions/ReflectionSource.cs 100% <100%> (ø)

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 aa9e428...bb4e2df. Read the comment docs.

@axunonb
Copy link
Member

axunonb commented Apr 12, 2021

Thanks, nice PR, will review this week.

@axunonb axunonb changed the base branch from main to version/v3.0 April 12, 2021 21:25
@axunonb axunonb changed the base branch from version/v3.0 to main April 12, 2021 21:27
@axunonb
Copy link
Member

axunonb commented Apr 13, 2021

Did you measure the performance gain with the type cache?
My first rough test loop says performance doubled.

@karljj1
Copy link
Collaborator Author

karljj1 commented Apr 13, 2021

I did test it on our version but I have not tested this one.

This was my results which also includes the object pooling.
image
I also disabled the threading support for the ListFormatter in our version as that is also quite slow and we don't use multithreading.

Unfortunately, I don't have the results from running the perf tests now but I did see similar results to what you describe.

You can see the reflection source has a huge perf improvement :)

@axunonb axunonb changed the base branch from main to version/v3.0 April 16, 2021 22:45
@axunonb
Copy link
Member

axunonb commented Apr 16, 2021

Really great PR, thanks!

@axunonb axunonb merged commit 8f5bcc1 into axuno:version/v3.0 Apr 16, 2021
axunonb added a commit that referenced this pull request Apr 16, 2021
* Added reflection cache
* Update for instance/class variables
Co-authored-by: axunonb <[email protected]>
Co-authored-by: Karl Jones <[email protected]>
axunonb added a commit to axunonb/SmartFormat that referenced this pull request Mar 10, 2022
* Added reflection cache

* Update for instance/class variables

Co-authored-by: axunonb <[email protected]>
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.

None yet

2 participants