Enum to ints or strings. #552
Replies: 2 comments 2 replies
-
Hello @littlefreak3000,
That's surprising, as ClearScript caches enum tokens in native code to avoid jumping to the managed side for token retrieval. Can you give us an idea about how you expose and access enums in script code (without JSON serialization)? Perhaps a minimal code sample? Thanks! |
Beta Was this translation helpful? Give feedback.
-
I have implemented this and I am seeing better execution times. I added to MarhalToScript:
I also tested just returning right out of the if instead of setting the value to obj, and it worked. Is there a reason not to do this. I see at the end of the function it is wrapped in a HostItem is this needed? Would it be better to do something like:
Obviously there is a lot of checks in this function and the function is ran for every variable passing the boundary so exiting as soon as you know the answer is best. But you dont bother wrapping bigintegers or datetime etc so is there harm in not wrapping an int or string? Thanks I'll be preparing a PR soon enough. |
Beta Was this translation helpful? Give feedback.
-
The DateTime to Date conversion sped things up so much. Before I was sending ticks and then converting them to Dates as this was faster then dealing with DateTime on the JS side. I am using ClearScript currently as a way for my users to inject custom functions into a processing loop. So I am passing an object to a function millions of time. So I've been testing all kinds of optimizations and what is faster.
Currently doing anything with enums it is faster to run utf8json convert the object to a json string (1000+ characters) and then call JSON.parse on the JS side to get my object. This puts the enums into strings. Its a shame as if I am doing anything other then dealing with enums then the standard way is 33% faster. I have read all the previous issues involving enums and have tried all the suggested options, but they all require crossing the JS/CS barrier and it seems there is a heavy performance hit anytime that is done. And that 33% value is only based on me making 1 switch statement for 1 enum if I wanna do that for multiple different enums who knows if those performance hits stack.
I dug deep enough to find when DateTime conversion was added and found the code that did it. Seems like it would be possible to do something similar to enums with a int cast. String casting could be a little harder, but some users might like that. A lot has happened since that conversion was added though and I can't seem to find where it is located in the current code base. If someone would point me in the right direction as the file it was originally in doesn't exist in the latest build. I'd gladly try my hand at implementing it as for my system it would be worth the billable hours to do so and I'll submit a PR when done. Though I bet someone more familiar with the code base might be able to implement it too. If this is considered out of scope for the project I would completely understand that as you have your solutions for enums already and they do work. I don't know how many people are concerned about performance like I might be.
Hell for what I am using this for even if you didn't accept the PR I'd happily patch each new release for myself. So again anyone who could point me to where those functions are in the current code base I'd appreciate it.
Beta Was this translation helpful? Give feedback.
All reactions