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

Performance improvements: Optimize built-in functions name checking and use ConcurrentDictionary<string, WeakReference<LogicalExpression>> at caching #114

Merged
merged 7 commits into from Mar 18, 2024

Conversation

gumbarros
Copy link
Member

@gumbarros gumbarros commented Mar 8, 2024

Before:
image

After:
(At IL it's optimized by string size)
image

@gumbarros gumbarros changed the title Optimize built-in functions to don't have unnecessary type unboxing to string. Optimize built-in functions to don't have unnecessary type checking to string. Mar 8, 2024
@gumbarros gumbarros changed the title Optimize built-in functions to don't have unnecessary type checking to string. Optimize built-in functions name checking Mar 8, 2024
@gumbarros gumbarros changed the title Optimize built-in functions name checking Performance improvements: Optimize built-in functions name checking and use ConcurrentDictionary Mar 9, 2024
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 96.00000% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 74.01%. Comparing base (c5fcc0e) to head (c745739).

❗ Current head c745739 differs from pull request most recent head 10d3d7e. Consider uploading reports for the commit 10d3d7e to get more accurate results

Files Patch % Lines
src/NCalc/Domain/EvaluationVisitor.cs 96.72% 1 Missing and 1 partial ⚠️
src/NCalc/Expression.cs 94.87% 0 Missing and 2 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #114      +/-   ##
==========================================
- Coverage   74.30%   74.01%   -0.30%     
==========================================
  Files          20       20              
  Lines        4480     4433      -47     
  Branches      274      255      -19     
==========================================
- Hits         3329     3281      -48     
  Misses       1021     1021              
- Partials      130      131       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ThomasHambach
Copy link
Contributor

Thanks for the contribution @gumbarros

You mention performance improvements, did you run any tests to confirm it runs faster?

@gumbarros
Copy link
Member Author

Thanks for the contribution @gumbarros

You mention performance improvements, did you run any tests to confirm it runs faster?

No, just checked the IL and checked the unit test of concurrency to see if everything is alright. Do you know how can I do a Benchmark to compare two NCalc versions?

@Bykiev
Copy link
Contributor

Bykiev commented Mar 14, 2024

Do you know how can I do a Benchmark to compare two NCalc versions?

You can use https://github.com/dotnet/BenchmarkDotNet library to measure performance with existing NuGet package

@yallie
Copy link
Member

yallie commented Mar 15, 2024

I'm sorry guys, I'm still feeling sick a bit and can't function properly.
I was going to merge all PRs and release it as a new version.
But looks like recent PRs have conflicts in the generated code due to grammar changes.
Could you give me a hand resolving the conflicts please?
Perhaps it's the matter of regenerating the parser/lexer classes.

PS. @gumbarros, @lucaschimweg — thanks a lot for your contributions! 🚀

…e-evaluation-visitor

# Conflicts:
#	src/NCalc/Domain/EvaluationVisitor.cs
#	src/NCalc/Expression.cs
@gumbarros
Copy link
Member Author

Ready to merge

@gumbarros gumbarros changed the title Performance improvements: Optimize built-in functions name checking and use ConcurrentDictionary Performance improvements: Optimize built-in functions name checking and use ConcurrentDictionary<string, WeakReference<LogicalExpression>> at caching Mar 18, 2024
@yallie yallie merged commit d18f965 into ncalc:master Mar 18, 2024
2 checks passed
Bykiev added a commit to Bykiev/NCalc2 that referenced this pull request Mar 19, 2024
Improve cache management code.

This PR is based on ncalc/ncalc#114
david-brink-talogy pushed a commit to sklose/NCalc2 that referenced this pull request Mar 22, 2024
* Improve cache management code

Improve cache management code.

This PR is based on ncalc/ncalc#114

* Update Expression.cs

* Cancel rename CleanCache method

* Remove cleanCache

* Use ConditionalWeakTable for cache

* Revert "Use ConditionalWeakTable for cache"

This reverts commit 8c3d4c5.

* Revert "Remove cleanCache"

This reverts commit 728dfd8.

* Remove new line
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

5 participants