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

Remove wasteful virtuals according to SizeBench #11889

Merged
3 commits merged into from Jan 7, 2022

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Dec 7, 2021

This commit removes some pure virtual base classes from conhost,
found with the help of SizeBench. This reduces binary size by 5kB.
The reduction in code size however is the main benefit of this.

Additionally this fixes a mysterious, undebuggable crash in
~RenderThread(), caused by a Control Flow Guard failure when
the class was destroyed over its IRenderThread interface.

PR Checklist

  • I work here
  • Tests added/passed

Validation Steps Performed

  • Printing text works ✅
  • Printing VT works ✅
  • Performance is alright ✅

@lhecker lhecker requested a review from miniksa December 7, 2021 02:46
@lhecker
Copy link
Member Author

lhecker commented Dec 7, 2021

@miniksa Some of these removals might be bad. Can you check which one's I need to revert?

For instance this pulls in interactivity/win32 code into interactivity/base and that's kinda whack.

On the other hand some of these changes actually make sense once you check neighboring code. For example, SetTerminalOwner(ITerminalOwner*) was changed to SetTerminalOwner(VtIo*) and that sounds weird right? Until you realize that the function in question is called VtEngine::SetTerminalOwner and suddenly it kinda makes sense.
(Also this PR removes almost a metric ton of code (literally actually, because it removes almost 1000 lines lol), so that's also nice.)

So... yeah. Just let me know what to revert and I'll do that. No hard feelings. The IRenderThread removal is the only thing that'd I'd like to really-really merge.

@lhecker lhecker force-pushed the dev/lhecker/remove-wasteful-virtuals branch from 2f0ff80 to f42c8fc Compare December 7, 2021 15:26
@github-actions

This comment has been minimized.

@lhecker lhecker added this to the Engineering Improvements 2021 milestone Dec 7, 2021
@lhecker lhecker force-pushed the dev/lhecker/remove-wasteful-virtuals branch from 07c82d3 to e352a45 Compare December 7, 2021 16:40
@lhecker lhecker added Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. Product-Conhost For issues in the Console codebase labels Dec 7, 2021
Copy link
Member

@miniksa miniksa left a comment

Choose a reason for hiding this comment

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

do I have hidden pending comments

EDIT: no it lost them somewhere damn it

src/server/ApiMessage.h Outdated Show resolved Hide resolved
src/host/_stream.cpp Outdated Show resolved Hide resolved
Copy link
Member

@miniksa miniksa left a comment

Choose a reason for hiding this comment

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

65/65. I think I called out the important bits.

@lhecker lhecker force-pushed the dev/lhecker/remove-wasteful-virtuals branch from e352a45 to 185064e Compare December 14, 2021 16:54
@github-actions

This comment has been minimized.

@lhecker lhecker force-pushed the dev/lhecker/remove-wasteful-virtuals branch from 185064e to 05ff1c0 Compare December 14, 2021 17:05
@lhecker lhecker force-pushed the dev/lhecker/remove-wasteful-virtuals branch from 05ff1c0 to cfab0f1 Compare December 14, 2021 17:06
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

I'm okay with this. I really liked how we used to have all these neat little silos that didn't know about the impl details of other parts of the codebase. But, I get that it's bad for performance, and we never really leveraged that siloing, so 🤷

@@ -31,7 +31,7 @@ namespace Microsoft::Console::Render
std::optional<CursorOptions> cursorInfo;
};

class IRenderEngine
class __declspec(novtable) IRenderEngine
Copy link
Member

Choose a reason for hiding this comment

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

Should we have been doing this just always? I literally had no idea this existed, but seems really valuable for interfaces

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we probably should ;P

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

wait I'm dismissing my own review since this still doesn't build yet, wanna make sure the headers don't get included in a totally bonkers fashion

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Dec 15, 2021
@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Dec 15, 2021
@lhecker lhecker marked this pull request as ready for review December 15, 2021 23:18
@lhecker
Copy link
Member Author

lhecker commented Dec 15, 2021

I fixed the compilation error btw. 🙂

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

I wish we could have the value of an interface (SPECIFICALLY: the restriction on what somebody holding a pointer can do. I don't care about swapping the impementation) without the cost.

@@ -31,7 +31,7 @@ namespace Microsoft::Console::Render
std::optional<CursorOptions> cursorInfo;
};

class IRenderEngine
class __declspec(novtable) IRenderEngine
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we probably should ;P

@@ -15,13 +15,13 @@ Author(s):

#pragma once

#include <../host/VtIo.hpp>
Copy link
Member

Choose a reason for hiding this comment

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

I know you've explained that these don't matter to this specific compiler, but I do think we should follow the prevailing style!

Copy link
Member

Choose a reason for hiding this comment

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

That is: "".

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually this is even worse! This file is src/renderer/vt/vtrenderer.hpp and I'm trying to include src/host/VtIo.hpp.

With "" this would then be a MS specific search path, because MSVC is the only compiler which allows "" includes to search in the current directories of previously included files. I've replaced it with "../../host/VtIo.hpp".

@@ -31,9 +31,14 @@ namespace TerminalCoreUnitTests
};
#endif

namespace Microsoft::Console::VirtualTerminal
{
class VtIo;
Copy link
Member

Choose a reason for hiding this comment

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

You included the header and forward-declared VtIo?

@DHowett
Copy link
Member

DHowett commented Dec 16, 2021

Also this PR removes almost a metric ton of code (literally actually, because it removes almost 1000 lines lol), so that's also nice.

Given that we are not making as extensive of changes as we were when you wrote this, are we still saving a whole 10kb?

@lhecker
Copy link
Member Author

lhecker commented Dec 16, 2021

I wish we could have the value of an interface (SPECIFICALLY: the restriction on what somebody holding a pointer can do. I don't care about swapping the impementation) without the cost.

Honestly, I feel like we can still do that. I just personally feel like we don't necessarily need to keep interfaces if no one has been using them for years. This makes it very unlikely anyone will make use of them in the next years either. If we need to turn any of these structs into an interface one day, it's likely easier to "interfacify" code than remove those interfaces, since at the point you "interfacify" them you already have the knowledge about the requirements of at least 2 implementations and not just the one for which it was originally written.

I'll fix the issues in a minute and go over the PR again.

@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jan 7, 2022
@ghost
Copy link

ghost commented Jan 7, 2022

Hello @DHowett!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 825efda into main Jan 7, 2022
@ghost ghost deleted the dev/lhecker/remove-wasteful-virtuals branch January 7, 2022 17:56
@ghost
Copy link

ghost commented Feb 3, 2022

🎉Windows Terminal Preview v1.13.10336.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. AutoMerge Marked for automatic merge by the bot when requirements are met Product-Conhost For issues in the Console codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants