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

Runtime conditional compilation (or removing CS0834) #7799

Closed
orthoxerox opened this issue Jan 6, 2016 · 3 comments
Closed

Runtime conditional compilation (or removing CS0834) #7799

orthoxerox opened this issue Jan 6, 2016 · 3 comments

Comments

@orthoxerox
Copy link
Contributor

There are at least two cases when I found it necessary to eliminate conditional checks from a function.

Case 1 was a game engine, where the main loop had to be streamlined as much as possible, so instead of checking the same settings sixty times per second (is raw input enabled, is custom message loop enabled, etc) the delegate was recompiled every time a setting was changed.

Case 2 was a banking software where each specific product got its own streamlined implementation of the business logic (both for performance and troubleshooting reasons).

Case 1 was written in C# and required using expression trees. The loop was small enough that it could be done.

Case 2 was written in PL/SQL, so it could utilize dynamic compilation. It was an error-prone mess for the same reasons C macros are, but I have no idea how this would have been done in C#.

To make something like Case 2 feasible in C#, I would need to be able to create expression trees from a multi-line lambdas. Building a tree-walker that eliminates conditionals from it would be simple enough.

Another option would be to give us an API that actually optimized compiled code (that worked with CIL, not Expressions) by fixing specific values and eliminating redundant checks. This would require first-class classes, so I guess it's something too big to ask.

@sharwell
Copy link
Member

sharwell commented Jan 6, 2016

To make something like Case 2 feasible in C#, I would need to be able to create expression trees from a multi-line lambdas.

Is this covered by Expression.Block?

@svick
Copy link
Contributor

svick commented Jan 6, 2016

This sounds like duplicate of #2060 to me.

@orthoxerox
Copy link
Contributor Author

@sharwell no, as you cannot use a real block as the RHS of the assignment.

@svick yes it does, thanks. I'll think about first-class classes some more and open a new issue if the idea starts to make sense.

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

3 participants