Skip to content

Update the mscorlib.md document.#36225

Merged
AaronRobinsonMSFT merged 4 commits intodotnet:masterfrom
AaronRobinsonMSFT:updatemscorlib_md
May 11, 2020
Merged

Update the mscorlib.md document.#36225
AaronRobinsonMSFT merged 4 commits intodotnet:masterfrom
AaronRobinsonMSFT:updatemscorlib_md

Conversation

@AaronRobinsonMSFT
Copy link
Member

@AaronRobinsonMSFT AaronRobinsonMSFT added the documentation Documentation bug or enhancement, does not impact product or test code label May 11, 2020
@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 5.0 milestone May 11, 2020
@ghost
Copy link

ghost commented May 11, 2020

Tagging subscribers to this area: @ViktorHofer
Notify danmosemsft if you want to be subscribed.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can have one.

There are many small ones like #33701 or #32722 done recently.

Out of the big ones:

Copy link
Member

@danmoseley danmoseley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Can you add an issue for that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #36238

@AaronRobinsonMSFT
Copy link
Member Author

Changes in source were only in comments.

@AaronRobinsonMSFT AaronRobinsonMSFT merged commit 99aae90 into dotnet:master May 11, 2020
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the updatemscorlib_md branch May 11, 2020 19:29
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Meta documentation Documentation bug or enhancement, does not impact product or test code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants