Consider using reflection to optimize code paths in stock scenarios
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 1.1k
- Avg merge
- 1d 13m
- Merged PRs (30d)
- 85
Description
WinForms is almost completely configurable but that comes at a performance cost. When we get windows messages (`WM_*`) we create event classes and jump through a lot of hoops that would not be necessary in a closed system.
For one example, getting a `WM_ERASEBKGND` often ends up being a `FillRect` on the passed in `HDC`. We could potentially avoid a lot of hoop jumping some allocations if we knew the `OnPaintBackground` was completely under our control.
We would pay up front for this sort of check, but could potentially earn it back quite quickly. The following code takes a couple of milliseconds on class creation:
``` C#
Type type = GetType();
_isTypeInAssembly = type.Assembly == typeof(Control).Assembly;
_isOnPaintBackgroundLocal = _isTypeInAssembly
|| type.GetMethod(
"OnPaintBackground",
BindingFlags.NonPublic | BindingFlags.Instance,
null,
new Type[] { typeof(PaintEventArgs) }, null
).DeclaringType.Assembly == typeof(Control).Assembly;
```
If we find measurable situations where we go "if only we knew this wasn't customized" this may be a strategy to attempt.
Contributor guide
Assessment
This issue has not been assessed yet.