Update the mscorlib.md document.#36225
Conversation
|
Tagging subscribers to this area: @ViktorHofer |
| First, remember that you should be writing as much as possible in managed code. You avoid a raft of potential GC hole issues, you get a better debugging experience, and the code is often simpler. It also continues the ongoing refactoring of SPCL into smaller layered fully [managed libraries](https://github.com/dotnet/runtime/src/libraries). | ||
|
|
||
| Reasons to write FCalls in the past generally fell into three camps: missing language features, better performance, or implementing unique interactions with the runtime. C# now has almost every useful language feature that you could get from C++, including unsafe code & stack-allocated buffers, and this eliminates the first two reasons for FCalls. We have ported some parts of the CLR that were heavily reliant on FCalls to managed code in the past (such as Reflection and some Encoding & String operations), and we want to continue this momentum. We may port our number formatting & String comparison code to managed in the future. | ||
| Reasons to write FCalls in the past generally fell into three camps: missing language features, better performance, or implementing unique interactions with the runtime. C# now has almost every useful language feature that you could get from C++, including unsafe code and stack-allocated buffers, and this eliminates the first two reasons for FCalls. We have ported some parts of the CLR that were heavily reliant on FCalls to managed code in the past (such as Reflection, some Encoding, and String operations) and we intend to continue this momentum. |
There was a problem hiding this comment.
Do we have a meta issue tracking components that we would like to port to managed? I am not sure we have one, but it feels like it would be worth having. @jkotas.
There was a problem hiding this comment.
Yes, we can have one.
There are many small ones like #33701 or #32722 done recently.
Out of the big ones:
- The top of the list is threadpool that is being worked on
- The next one with the best cost/benefit is probably Reflection.Emit (System.Reflection.Emit.AssemblyBuilder.Save #15704)
danmoseley
left a comment
There was a problem hiding this comment.
thanks for improving docs.
Remove no longer relevant details.
| QCalls are the preferred mechanism going forward. You should only use FCalls when you are "forced" to. This happens when there is common "short path" through the code that is important to optimize. This short path should not be more than a few hundred instructions, cannot allocate GC memory, take locks or throw exceptions (`GC_NOTRIGGER`, `NOTHROWS`). In all other circumstances (and especially when you enter a FCall and then simply erect HelperMethodFrame), you should be using QCall. | ||
|
|
||
| FCalls were specifically designed for short paths of code that must be optimized. They allowed you to take explicit control over when erecting a frame was done. However it is error prone and is not worth it for many APIs. QCalls are essentially P/Invokes into CLR. | ||
| FCalls were specifically designed for short paths of code that must be optimized. They allowed explicit control over when erecting a frame was done. However, it is error prone and not worth the complexity for many APIs. QCalls are essentially P/Invokes into the CLR. In the event the performance of an FCall is required consider creating a QCall and marking it with [`SuppressGCTransitionAttribute`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.suppressgctransitionattribute). |
There was a problem hiding this comment.
Not necessarily in this doc but something to think about: The normal QCALL_CONTRACT and QCALL_CHECK macros specify the GC mode so they can't be used on QCalls that use SuppressGCTransition. We should add macros for "suppressed-gc-transition QCall" contracts/checks to make it easier for developers to define them correctly.
There was a problem hiding this comment.
Agreed. Can you add an issue for that?
|
Changes in source were only in comments. |
/cc @jkotas @jkoritzinsky @elinor-fung