InkCanvas - CPU Hungry
I have a UI with an InkCanvas viewed through a VisualBrush. With only a few strokes on the canvas, CPU utilization approaches 60%. When I setmyInkCanvas.Visibility = Visibility.Hidden then CPU utilization drops.
I may be able to make a small mockup that will demonstrate the behavior, but I would hope it could be solved without that.
This is a snapshot of the stack from the offending thread (which I can't make heads or tails out of):
ntoskrnl.exe!KiDispatchInterrupt+0x7f MilCore.dll!MilChannel_CommitChannel+0x12b ntoskrnl.exe!KeInitializeTimer+0x107 ntoskrnl.exe!KeUserModeCallback+0x87 ntoskrnl.exe!KeUserModeCallback+0xbd MilCore.dll!MilChannel_CommitChannel+0x12b MilCore.dll!MilChannel_CommitChannel+0x1f6 MilCore.dll!MilChannel_CommitChannel+0xf1 MilCore.dll!MilChannel_MarshalType+0x2d6 MilCore.dll!MilChannel_MarshalType+0x4a6 MilCore.dll!MilResource_SendCommandBitmapSource+0xa300 MilCore.dll!MilResource_SendCommandBitmapSource+0xa47f MilCore.dll!MilResource_SendCommandBitmapSource+0xa4f0 MilCore.dll!MilResource_SendCommandBitmapSource+0xa563 MilCore.dll!MilResource_SendCommandBitmapSource+0xac65 MilCore.dll!MilChannel_SetNotificationWindow+0x45c4 MilCore.dll!MilChannel_SetNotificationWindow+0x36b4 MilCore.dll!MilTransport_InitializeTransportManager+0x9125 MilCore.dll!MilTransport_InitializeTransportManager+0x91c5 MilCore.dll!MilChannel_SetNotificationWindow+0x404a MilCore.dll!MilChannel_SetNotificationWindow+0x4130 MilCore.dll!MilChannel_SetNotificationWindow+0x208e MilCore.dll!MilChannel_SetNotificationWindow+0x21d9 MilCore.dll!MilChannel_SetNotificationWindow+0x1abe MilCore.dll!MilChannel_SetNotificationWindow+0x1e34 MilCore.dll!MilChannel_SetNotificationWindow+0x38da MilCore.dll!MilChannel_SetNotificationWindow+0xf8a MilCore.dll!MilChannel_SetNotificationWindow+0x433c MilCore.dll!MilChannel_SetNotificationWindow+0x1413 MilCore.dll!MilChannel_SetNotificationWindow+0xa25 MilCore.dll!MilChannel_SetNotificationWindow+0xb3b MilCore.dll!MilChannel_AppendCommandData+0xb8a MilCore.dll!MilChannel_AppendCommandData+0xa18 MilCore.dll!MilChannel_AppendCommandData+0xacb MilCore.dll!MilChannel_AppendCommandData+0x8a4 MilCore.dll!MilChannel_AppendCommandData+0x991 MilCore.dll!MilChannel_AppendCommandData+0x691 KERNEL32.dll!GetModuleFileNameA+0x1b4 MilCore.dll!MilCompositionEngine_DeinitializePartitionManager+0x125a
Hi Nathan,
there has been a lot of perf optimization work for both MIL (Media Integration Layer) and Ink after the Febuary CTP has been released.
On current internal builds I am not seeing any unusual CPU utilization when viewing an InkCanvas through a VisualBrush.
Could you provide a few more details on your scenario. Does it involve any animations? What hardware and OS are you running on? Do you see perf problems on your computer when running the simplistic InkCanvas/VisualBrush sample I have pasted below?
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<StackPanel>
<InkCanvas Name="ic" Height="200" Background="Beige"/>
<Canvas Height="200">
<Canvas.Background>
<VisualBrush Visual="{Binding ElementName=ic}"/>
</Canvas.Background>
</Canvas>
</StackPanel>
</Page>
Thanks - Stefan Wick
Thank you for the help Stefan.
I have not yet managed to reproduce the effect in a simpler app, though there are a few things that I haven’t tried yet.We have, however, made the discovery that our problem exists on some computers (all tablets or with the SDK) but not on others (regular laptops).The InkCanvas is using a custom stylus plugin, and the visual brush is animated.The CPU, though, continues to run when the program in minimized and not animating.
Tomorrow I will try a simpler app with the StylusPlugIn, as that is what I haven't tested in isolation yet.
The computers that have the problem include:
Two Tecra M4s, 2.0/1.8Ghz PM and GeForce 6600/6200 Go respectively, Tablet 2005.
One Motion M1400 with Tablet 2005.
One Alienware laptop, 3.0 Ghz P4, Radeon 9600 Pro, XP Sp2 w/ Tablet PC SDK
The computers without the problem include:
Dell laptop, 1.6Ghz PM, Radeon X300, XP Sp2
Thanks for trying to track this down, Nathan.
If you prefer, you can send me your project offline and I'll post back to the forum with the results of our investigation. Just remove "online." from my display e-mail name to get my e-mail address.
I want to make sure we have your scenario covered in our performance testing.
Thanks - Stefan Wick
I think I found it. I seem to have had some runaway code in my Stylus plug-in. I still have not figured out why it did not affect our Dell laptop, but this was certainly our problem.
Thanks for the help! Our project is an Imagine Cup entry, you can come to the project fair on May 5th (Building 33 ?) if you are interested to see what we have done with Ink and Avalon. =)
- Nathan Bales
Cool! I have marked this on my calendar.
Stefan Wick
Hi Stefan,
Thought you'll be interested to know that I have the same general situation running Avalon Patient Monitoring on WinXP. I've downloaded the runtime just today. The CPU utilization in 95% total with around 80% on the app. It seems that if the runtime simply takes over whatever CPU is available.
Running on Compaq EvoN 620c with 2G RAM, 1.5 GHz Intel Pentium M, Mobility Radeon 7500.
Stack shows that the time is divided between mscoree.dll!CoreExeMain (about 30% or 40%) and MilCore.dll!MilChannel_SetNotificationWindow+0x122 (about 50%). Typical stack from MilCore.dll is pasted below (I was using Sysinternals' Process Explorer)
ntoskrnl.exe!DbgLoadImageSymbols+0x42
MilCore.dll!MilUtility_PathGeometryHitTest+0xed97
MilCore.dll!MilUtility_PathGeometryHitTest+0xee17
MilCore.dll!MilUtility_PolygonHitTest+0x887
MilCore.dll!MilUtility_PathGeometryHitTest+0xec17
MilCore.dll!MilUtility_PathGeometryHitTest+0xebe0
MilCore.dll!MilUtility_PathGeometryHitTest+0xeb98
MilCore.dll!MilUtility_PathGeometryHitTest+0xf0ac
MilCore.dll!MilUtility_PathGeometryHitTest+0xe1c4
MilCore.dll!MilUtility_PathGeometryHitTest+0xdd87
MilCore.dll!MilUtility_PathGeometryHitTest+0xde7a
MilCore.dll!MilUtility_PathGeometryHitTest+0xdef2
MilCore.dll!MilResource_CreateOrAddRefOnChannel+0x4447
MilCore.dll!MilResource_CreateOrAddRefOnChannel+0x24fc
MilCore.dll!MilResource_CreateOrAddRefOnChannel+0xb83
MilCore.dll!MilResource_CreateOrAddRefOnChannel+0x1f69
MilCore.dll!MilResource_CreateOrAddRefOnChannel+0x1e4d
MilCore.dll!MilResource_CreateOrAddRefOnChannel+0x4074
MilCore.dll!MilResource_CreateOrAddRefOnChannel+0x402d
MilCore.dll!MilResource_CreateOrAddRefOnChannel+0x8fb0
MilCore.dll!MilResource_CreateOrAddRefOnChannel+0x4922
MilCore.dll!MilResource_CreateOrAddRefOnChannel+0x7392
MilCore.dll!MilResource_CreateOrAddRefOnChannel+0x8ab1
MilCore.dll!MilResource_CreateOrAddRefOnChannel+0x8bcf
MilCore.dll!MILQueryInterface+0x2b83
MilCore.dll!MILQueryInterface+0x2984
MilCore.dll!MILQueryInterface+0x2f82
MilCore.dll!MILQueryInterface+0x2f28
MilCore.dll!MILQueryInterface+0x2eab
MilCore.dll!MILQueryInterface+0x2d89
MilCore.dll!MilChannel_SetNotificationWindow+0x140
KERNEL32.dll!GetModuleFileNameA+0x1b4