-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve non agile object performance (#1106)
* CompareExchange * Add benchark for non agile objects * Add another benchmark and cleanup code * Minor changes * Agile reference optimizations * Variable rename * Add back fallback Co-authored-by: Joshua Larkin <70237359+j0shuams@users.noreply.github.com>
- Loading branch information
1 parent
0bf67c1
commit 25d83dd
Showing
5 changed files
with
231 additions
and
139 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,66 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using System.Threading; | ||
|
||
namespace Benchmarks | ||
{ | ||
[MemoryDiagnoser] | ||
public class NonAgileObjectPerf | ||
{ | ||
AutoResetEvent createObject; | ||
AutoResetEvent exitThread; | ||
AutoResetEvent objectCreated; | ||
Thread staThread; | ||
private volatile Windows.UI.Popups.PopupMenu nonAgileObject; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
createObject = new AutoResetEvent(false); | ||
exitThread = new AutoResetEvent(false); | ||
objectCreated = new AutoResetEvent(false); | ||
staThread = new Thread(new ThreadStart(ObjectAllocationLoop)); | ||
staThread.SetApartmentState(ApartmentState.STA); | ||
staThread.Start(); | ||
} | ||
|
||
[GlobalCleanup] | ||
public void Cleanup() | ||
{ | ||
exitThread.Set(); | ||
createObject.Set(); | ||
} | ||
|
||
private void ObjectAllocationLoop() | ||
{ | ||
while (createObject.WaitOne() && !exitThread.WaitOne(1)) | ||
{ | ||
createObject.Reset(); | ||
nonAgileObject = new Windows.UI.Popups.PopupMenu(); | ||
CallObject(); | ||
objectCreated.Set(); | ||
} | ||
} | ||
|
||
private int CallObject() | ||
{ | ||
return nonAgileObject.Commands.Count; | ||
} | ||
|
||
[Benchmark] | ||
public void ConstructAndQueryNonAgileObject() | ||
{ | ||
createObject.Set(); | ||
objectCreated.WaitOne(); | ||
CallObject(); | ||
objectCreated.Reset(); | ||
} | ||
|
||
[Benchmark] | ||
public void ConstructNonAgileObject() | ||
{ | ||
createObject.Set(); | ||
objectCreated.WaitOne(); | ||
objectCreated.Reset(); | ||
} | ||
} | ||
} |
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.