3. Why performance matters
Everyone loves performance
Performance=money
Bing - 2 seconds slower – 4.3% drop in revenue
Google – 400ms slower – 0.6% drop in searches
Yahoo! – 400ms slower – 5-9% drop in full page traffic
Mozilla – 2.2 seconds faster – increased download conversion
15.4%
Site speed is now taken into account in search rankings
5. Our Demo APP
Uses StackOverflow.com’s data
Groups users by location
Displays user locations in a chart
Will work in a client/server architecture
Has performance issues
8. Client-Server communication
Grouping data on the server
List<T>
LINQ to Objects
Dictionary<T,V>
Retrieving only location-related data on the client
DEMO
13. Small Object Heap (SOH)
GC
SmallObject ObjectB = new
ObjectA
SmallObject();
Global
Objects Small Object Heap
Next Object Pointer
ObjectE
Next Object Pointer
Stack
ObjectD
Next Object Pointer Static
Objects
ObjectC
Next Object Pointer
ObjectB ObjectB
Next Object Pointer
ObjectA Root Reference
ObjectA
Next Object Pointer Child Reference
14. GC - Gen 0
2
1
Generations
Small Object Heap
Gen 0 Next Object Pointer
Global ObjectD
Objects
ObjectC
Next Object Pointer
Gen 1
Static
Stack Objects
ObjectB
Gen 2
Root Reference
ObjectA
15. Large Object Heap (LOH)
GC- Gen2
LargeObject ObjectD= new
LargeObject();
Free space table
Global
Objects Large Object Heap From To
5727400
425000 16777216
ObjectD
94208 182272
Stack Free space
ObjectC ObjectC
Free space
ObjectB
ObjectB
ObjectA
ObjectA
16. GC
Finalization
FinObject ObjectE = new FinObject();
Finalization
Queue
Small Object Heap
Gen 0
Global
Objects ObjectE Finalize() ObjectE
fReachable
ObjectD
Queue
Finalizer
Stack ObjectC thread
Gen 1
ObjectB
ObjectB
ObjectA ObjectA
17. Finalization
public class Test {
~Test()
{
Cleanup ();
}
private void Cleanup()
{
// clean up unmanaged resources
}
}
18. Disposable pattern
public class Test : IDisposable{
~Test()
{
Cleanup (false);
}
private void Cleanup(bool codeDispose)
{
if (codeDispose)
{
// dispose managed resources
}
// clean up unmanaged resources
}
public void Dispose()
{
Cleanup (true);
GC.SuppressFinalize(this);
}
}
20. JITing Console
Managed EXE
static void WriteLine();
static void Main(){
Console.WriteLine(“Hello”); JITCompiler
Console.WriteLine(“GoodBye”);
} static void WriteLine(string);
JITCompiler
MSCorEE.dll
(remaining members)
JITCompiler function{ …
1. Look up the called method in the metadata
2. Get the IL for it from metadata
3. Allocate memory
4. Compile the IL into allocated memory
5. Modify the method’s entry in the Type’s
table so it points to allocated memory Native
6. Jump to the native code contained inside CPU
the memory block. instr.
}
21. JITing Console
Managed EXE
static void WriteLine();
static void Main(){
Console.WriteLine(“Hello”); JITCompiler
Console.WriteLine(“GoodBye”);
} static void WriteLine(string);
Native
MSCorEE.dll
(remaining members)
JITCompiler function{ …
1. Lookup the called method in the metadata
2. Get the IL for it from metadata
3. Allocate memory
4. Compile the IL into allocated memory
5. Modify the method’s entry in the Type’s
table so it points to allocated memory Native
6. Jump to the native code contained inside CPU
the memory block.} instr.