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 problem #16

Open
DrEight opened this issue Jun 4, 2018 · 3 comments
Open

Performance problem #16

DrEight opened this issue Jun 4, 2018 · 3 comments

Comments

@DrEight
Copy link

DrEight commented Jun 4, 2018

I notice a performance bottleneck passing to JS a Dictionary<string,string> of 1000 items.
So after a long investigation I found that the culprit is the context switching registering the type.
Every 'WriteProperty' does a context switch. I don't understand why.
So I removed the context switch ( I exposed the 'Enter' and 'Leave' to the rules and I created a 'WriteProperty' that does not switch the context.
The difference is impressive: with the context switch, passing the dictionary it takes 2500ms. Without 15ms.
Do I miss something, or is it a bug ?

@JohnMasen
Copy link
Owner

hi DrEight,
Thanks for your message, This behavior is by design. it sacrifice the performance to make the library thread safe. By wrapping each engine operation in a context switch. user do not need to call "Leave" manually( it happens a lot and hard to debug).
I'm planning to add a set of "BatchXXX" to provide a walkaround in future version. But due to my limited bandwidth, I can't tell when it will be finished.

@DrEight
Copy link
Author

DrEight commented Jun 7, 2018

Thank you for the clarification. I've already implemented a kind of 'batch' call, but it is not very elegant, so I'll don't create a pull request.

@JohnMasen
Copy link
Owner

  • there's another hack way. you can wrap your call into ContextSwitchService.With(). The library will ignore nested "Enter","Leave" method.

  • please avoid any long running code inside the With() method if you have multi thread call to the engine as the With() will cause lock.

to improve performance, the best way is use memorymapped object, you can see the unit test for reference. The sample will be published in next phase, hope I can finish it this month.

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

No branches or pull requests

2 participants