Comments (6)
The be honest. I have never tested it to be the case. The main potential issue I see is with the caching of generated delegates. But I think it can definitely be made thread safe without a performance impact.
For which reason do you need to have it thread-safe?
from jace.
just to avoid unnecessary allocations. e.g. i could have a static engine .
from jace.
Thread safety would also make the cache usage more efficient. In my current implementation I am not sharing the CalculationEngine at all between objects. I could definitely do something about this already, but the thread safety would make sense from caching point of view too. Now the MemoryCache
and the ConcurrentDictionary
it uses are created per CalculationEngine
instance.
I have a usa case which relies quite heavily on Jace formula calculations and I can see that lots of time is spent on the DynamicCompiler.BuildFromula()
.
Here converting the cache to be a singleton/thread safe might also do the trick. It could be even configured in the JaceOptions
if the cache is to be handled as singleton or not. Another option would be to use .Net MemoryCache
directly and rely on it's cleanup and thread safety mechanisms. Built formulas should be thread safe already as they are just pure functions.
In the my case of which you can see the performance above I have only 32 different formulas, but 1168 instances of the engine.
from jace.
I could improve my code by creating the Engine per user, so I would be ensured to have no concurrency issues, but even that approach leaves two problems.
- There is a performance penalty for new user sessions.
- There is memory overhead to even in having the cache per user.
I my case I think I could even have all the formulas cached as I have maximum of ~1900 formulas, but I think the real number is even much lower as that 32 different formulas for one use case already has almost maximum complexity. I have roughly 60 other cases for the formulas and they are much simpler mostly.
from jace.
Ah, and I did notice I did invalid lookup to the .Net documentation. .Net Standard does not have the MemoryCache, so that must be why ConcurrentDictionary is used. So looking now more into the approach of making it static.
from jace.
As for the thread safety in general. It would seem to me that ConstantRegistry
for one would need work to be thread safe. And FunctionRegistry
could potentially be even more problematic if shared. But if ommitting use of those two features it could be possible to make the engine a singleton. This is somewhat risky though. Maybe in that case there should be separate implementation of the CalculationEngine
, something like ConcurrentCalculationEngine
that would ommit the functionality that is not supported.
from jace.
Related Issues (20)
- Can we make Random overrideable? HOT 3
- Bitwise operations
- Non base-10 numbers
- Matrix & display function itself
- Override operators HOT 2
- Feature Request: Option to set calc trigonomic functions with degrees (not radian) HOT 1
- Wrong precendence for unitary minus and exponential
- Invalid floating point numbers cause InvalidOperationException
- Problems with ambiguity of e
- Invalid scientific notation leads to IndexOutOfBoundsException instead of ParseException
- Upgrade to NetStandard 2.0 HOT 2
- Interpreter.BuildFormula does not work with constants
- Is this project still being updated? HOT 2
- Runtime Error : Could not load file or assembly System.Runtime HOT 2
- JaceOptions case sensitivity does not get applied to FunctionRegistry or ConstantRegistry on engine constructor HOT 4
- Bug in operators precedence HOT 17
- Request for dynamic variables
- PEMDAS HOT 2
- Introducing _sonic_, a maintained Jace.NET fork/successor HOT 1
- avg function not working HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jace.