forked from microsoft/CsWinRT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the performance of invoking events (microsoft#1042)
* Event improvements * More optimizations. * Switch to ThreadStatic * Move to a version of CreateCCW that avoids creating an object to do a QI * Remove benchmark which keeps adding 100s of events to the same event source * Add comment. * PR feedback. * Fix build
- Loading branch information
1 parent
8954084
commit ec2966b
Showing
27 changed files
with
270 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using BenchmarkComponent; | ||
using BenchmarkDotNet.Attributes; | ||
using System; | ||
|
||
namespace Benchmarks | ||
{ | ||
[MemoryDiagnoser] | ||
public class EventPerf | ||
{ | ||
ClassWithMarshalingRoutines instance; | ||
int z2; | ||
ClassWithMarshalingRoutines instance2; | ||
int z4; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
instance = new ClassWithMarshalingRoutines(); | ||
System.EventHandler<int> s = (object sender, int value) => z2 = value; | ||
instance.IntPropertyChanged += s; | ||
|
||
instance2 = new ClassWithMarshalingRoutines(); | ||
System.EventHandler<int> s2 = (object sender, int value) => | ||
{ | ||
if (sender == this) | ||
z4 = value; | ||
else | ||
z4 = value * 3; | ||
}; | ||
instance2.IntPropertyChanged += s2; | ||
} | ||
|
||
[Benchmark] | ||
public object IntEventOverhead() | ||
{ | ||
ClassWithMarshalingRoutines instance = new ClassWithMarshalingRoutines(); | ||
int z; | ||
System.EventHandler<int> s = (object sender, int value) => z = value; | ||
return instance; | ||
GC.KeepAlive(s); | ||
} | ||
|
||
[Benchmark] | ||
public object AddIntEventToNewEventSource() | ||
{ | ||
ClassWithMarshalingRoutines instance = new ClassWithMarshalingRoutines(); | ||
int z; | ||
System.EventHandler<int> s = (object sender, int value) => z = value; | ||
instance.IntPropertyChanged += s; | ||
return instance; | ||
} | ||
|
||
[Benchmark] | ||
public object AddMultipleEventsToNewEventSource() | ||
{ | ||
ClassWithMarshalingRoutines instance = new ClassWithMarshalingRoutines(); | ||
int z; | ||
double y; | ||
System.EventHandler<int> s = (object sender, int value) => z = value; | ||
instance.IntPropertyChanged += s; | ||
System.EventHandler<double> t = (object sender, double value) => y = value; | ||
instance.DoublePropertyChanged += t; | ||
return instance; | ||
} | ||
|
||
[Benchmark] | ||
public object AddAndInvokeIntEventOnNewEventSource() | ||
{ | ||
ClassWithMarshalingRoutines instance = new ClassWithMarshalingRoutines(); | ||
int z; | ||
System.EventHandler<int> s = (object sender, int value) => z = value; | ||
instance.IntPropertyChanged += s; | ||
instance.RaiseIntChanged(); | ||
return instance; | ||
} | ||
|
||
[Benchmark] | ||
public int InvokeIntEvent() | ||
{ | ||
instance.RaiseIntChanged(); | ||
return z2; | ||
} | ||
|
||
[Benchmark] | ||
public int InvokeIntEventWithSenderCheck() | ||
{ | ||
instance2.RaiseIntChanged(); | ||
return z4; | ||
} | ||
|
||
[Benchmark] | ||
public object AddAndRemoveIntEventOnNewEventSource() | ||
{ | ||
ClassWithMarshalingRoutines instance = new ClassWithMarshalingRoutines(); | ||
int z; | ||
System.EventHandler<int> s = (object sender, int value) => z = value; | ||
instance.IntPropertyChanged += s; | ||
instance.IntPropertyChanged -= s; | ||
return instance; | ||
GC.KeepAlive(s); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.