Optimize Switch with OpCodes.Switch
Use Switch IL Code for Integer, long, ... (if possible). When int difference is less than 3 it should be used!
See the #133, #397 to reference the other Switch features
Hello,
I came across this issue and was wondering if you're planning to pick this up? We have some bits of generated code which would heavily benifit from using switch-statements. At the moment, we're calculating the density of our cases and fallback to .NET's Compile method when it exceeds a threshold of 70%. We prefer to use the FastExpressionCompiler, but our code runs faster when switch-statements can be emitted. We have a high performance data processing pipeline were the generated code will be executed many many times in a short period.
Thanks in advance!
Yes, it is planned with the priority depending on the demand. Now, I will pick it up sooner. Btw, PRs are welcome.
Alright, thanks! I'm a bit short in time atm, but I would love to submit a PR. If I'm able to find some time I'll definitely have a look at it.
@dadhi I've made a start for the switch-opcode support. ~It does't work now as it yields an InvalidProgramException which I have to look at.~ (not anymore :)) I got a few questions:
- you got everything in one big file, do you mind that the support for switches will be moved to other files/classes? I think this will make it easier to extend the support for switches in later releases, as it's likely to grow significantly if you want to add support for bucketing, string-length swtiches or more smart switch usages.
- I don't fully understand the output of the PrintIL method, it seems that it's printing a lot more than I'm actually emititing. Can I safely use that method for debugging purposes or should I rely on the Demit methods?
- I'm using JetBrains Rider, any recommended settings to make working with large files a bit easier? Rider becomes a bit slow during editing and I'm not getting all editor support I normally get (this is not the reason of question 1 btw).
Here's what I have now: https://github.com/dadhi/FastExpressionCompiler/compare/master...victorr99:FastExpressionCompiler:feature/swtich
The implementation is quite straightforward: it compiles a jump table and emits the switch statement. I think support for all integer types should work. I'm not implementing bucketing (thus: if (value < 50) { switch ... } else if (value < 100) { switch ... } ) nor string-length switches.
Hi and thanks for the work. I will look into it a bit later when I have time. Quick answers for 1 and 3.
- No, I won't do this just for the switch.
- It sucks actually, I don't know how to help here. JetBrains should consider performance as a productivity feature. Personally, I am using VSCode. It works.
Here's what I have now: https://github.com/dadhi/FastExpressionCompiler/compare/master...victorr99:FastExpressionCompiler:feature/swtich
Thanks for the work, I see that you did a lot. I will use it as the basis to drive my implementation from here.
Thanks a lot, I'm looking forward for the actual implementation and release!
Please let me know if you've any questions about this initial implementation.