Performance-effective Fluent API support #7841
Replies: 4 comments 1 reply
-
How exactly does this proposal address performance? And what benchmark numbers do you have to back up that claim? |
Beta Was this translation helpful? Give feedback.
-
What are the fluent methods that are currently used in hot loops? Something that performs network IO, like HttpRequest, won't really benefit from nanoseconds shaved off by not returning |
Beta Was this translation helpful? Give feedback.
-
public void fluent(this) Url(string requestUri) {} Syntax is wierd. It's a void but not really void and you have to type fluent for some reason just to make compiler think of it as returning ThisType. Why not just public this (or self or whatever "ThisType" is called) FluentMethod() { ... } This is basically what people in those discussions you mentioned ask for. With Roles the same syntax can be reused everywhere. And there is no need to introduce a keyword for a library concept, not a language/compiler one. I also don't see any performance benefit. If you're going for full perf you most likely will do whatever necessary to make your builder calls inlineable within a method boundary. Any excessive temps will be removed by native compiler anyway. |
Beta Was this translation helpful? Give feedback.
-
Sorry, the main idea is not about performance, I shouldn’t have written about it. The main idea is about the convenient use and writing of one code for both the regular style code and fluent style code. I will rewrite my proposal. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Updated: Fluent API support for static methods
The fluent API is one of the most commonly used design patterns in C#. It is elegant, and expressive and makes the code read like prose. Using extensively and ubiquitously in libraries and public APIs.
However, creating a fluent API can require a lot of ceremony and less efficient performance than a non-fluent API.
I suggest adding the
fluent
modifier to add performance-effective Fluent API support.The
void fluent(this)
modifier at method return specification means that the method returnsvoid
and the compiler will substitute the specified parameterthis
after calling the method to call the next method:The
void fluent(paramName)
modifier at method return specification means that the method returnsvoid
and the compiler will substitute the specified parameterparamName
after calling the method to call the next method.The
void fluent(paramName)
modifier at method return specification is also like thethis someType paramName
modifier in the extension methods but it is used only to chain fluent methods and does not mean that you create an extension method forsomeType
type.Also, we can add performance-effective fluent methods to struct:
See the motivation part of the #7325 language idea also.
See these discussions #902 #311 #252 #7231 #169 also.
Beta Was this translation helpful? Give feedback.
All reactions