ChakraCore.NET icon indicating copy to clipboard operation
ChakraCore.NET copied to clipboard

Performance problem

Open DrEight opened this issue 7 years ago • 3 comments

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 ?

DrEight avatar Jun 04 '18 12:06 DrEight

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.

JohnMasen avatar Jun 07 '18 01:06 JohnMasen

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.

DrEight avatar Jun 07 '18 08:06 DrEight

  • 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.

JohnMasen avatar Jun 07 '18 11:06 JohnMasen