WPF - typing in textbox is slow, just me?

E

eselk2003

After reading the book "Sams teach yourself WPF" cover-to-cover over
my xmas vacation I decided to build the most basic of EXEs just to see
how it would run on different PCs with different versions of .NET
installed. I just used VS 2008 to create the most basic WPF
application with just one TextBox control centered on the main window,
pretty much:

1. Created new WPF app from the File->New Project option.

2. Dragged a TextBox from the control box and dropped it on the main
window.

3. Changed the build mode to Release instead of debug, then built the
EXE.

The EXE is tiny, about 13KB.

I copied just the EXE to 2 different test PCs, one running XP SP3, and
another running Vista.

On either of these PCs I can type in Notepad or Microsoft Word (2000
on XP, 2007 on Vista) and the display is able to keep up with my
typing (about 60 words per minute).

However, my little WPF app, when I type in the text box, it can't keep
up. By the time I've typed 10 words, the display is already a full
word behind.

....as I've been typing this message using Google's interface inside
IE6 on the test XP system, it keeps up with my typing, and this window
has a lot more going on than my test app.

Has anyone else noticed this? Is there some "make my app run super
slow" setting that is enabled by default and I just need to turn it
off? =]

I selected .NET 3.5 when creating the new project in VS 2008, and the
systems I'm testing on don't have any weird/BETA versions of the run-
times that I know of. They are actually "pretty fast" as far as other
applications I use them for (Office apps), not top of the line or
anything, but I would expect just a window with a text box (my test
app) to work well even on a pretty low-end system.

Here is the XAML (I tried with and without spell checking enabled,
didn't make a difference):

<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
WindowStartupLocation="CenterScreen" WindowState="Maximized"
FocusManager.FocusedElement="{Binding ElementName=TextBox1}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="74*" />
<ColumnDefinition Width="204*" />
</Grid.ColumnDefinitions>
<TextBox Margin="10" Name="TextBox1"
SpellCheck.IsEnabled="true" Grid.ColumnSpan="2"
VerticalScrollBarVisibility="Auto" TextWrapping="Wrap"
AcceptsReturn="true" AcceptsTab="true" FontSize="14">
</TextBox>
</Grid>
</Window>
 
E

eselk2003

Also, and I should have done this before my first post, even with more
"normal" looking XAML, it is still slow, here is a better example of
some simple XAML that I've tested (got rid of the grid and just used a
simple panel).

<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
WindowStartupLocation="CenterScreen" WindowState="Maximized"
FocusManager.FocusedElement="{Binding ElementName=TextBox1}">
<StackPanel>
<TextBox Margin="10" Name="TextBox1"
SpellCheck.IsEnabled="true" VerticalScrollBarVisibility="Auto"
TextWrapping="Wrap" AcceptsReturn="true" AcceptsTab="true"
FontSize="14" Height="500px" />
</StackPanel>
</Window>
 
N

not_a_commie

My first question is what graphics card are you using? Second, do you
have the right driver for it? Third, is it still slow without the
SpellCheck? Fourth, do you have .Net 3.5 SP1 installed?
 
E

eselk2003

My first question is what graphics card are you using?

Display properties just says "Generic VGA Driver" on the Vista PC, and
XP just says "UniChrome Pro IGP", which probably isn't very helpful,
but even if I could open the cases right now I'm not sure I could tell
exactly what cards they are anyway.
Second, do you have the right driver for it?

Probably not, but see my general comment at the end.
Third, is it still slow without the SpellCheck?
Yes.

Fourth, do you have .Net 3.5 SP1 installed?

No. The Vista PC just has the default .Net version, at least I'm
pretty sure it does because when I got to "uninstall programs" the
list says "No programs are installed on this computer", and I think
service packs are usually included in that list (.NET as well as
Windows OS).

The main thing that surprised me was that both of these PCs run other
programs that are much more involved (like Excel and Word) without
this noticable delay when typing. Also, in my experience, if the
graphics card is slow or having issues, Vista itself (control panel,
explorer, start menu, etc) runs like a dog... and on the Vista system
I tested with, the Vista screens respond well ("snappy").

If I had another program that I knew used WPF, then I guess I'd have
something else to compare with, to at least know if I had a weird
compiler setting or something.

I'll try updating my XP system to .NET 3.5 SP1 now, and also see if I
can find another small WPF app that someone else has built to check...
I'll post the results.
 
E

eselk2003

On either of these PCs I can type in Notepad or Microsoft Word (2000
on XP, 2007 on Vista) and the display is able to keep up with my
typing (about 60 words per minute).

However, my little WPF app, when I type in the text box, it can't keep
up.  By the time I've typed 10 words, the display is already a full
word behind.

As not_a_commie suggested, I updated to .NET 3.5 SP1. That didn't
make a difference.

Then I also noticed that anytime my WPF window was the foreground
window, the mouse cursor would stutter as I moved it across the
screen. If another window is in the foreground, even with WPF window
in the background, this doesn't happen.

I tried turning off all hardware acceleration under the system display
properties, on my XP test system (didn't try on Vista yet), and that
resolved the issue. The WPF window is now as fast as I would expect
(about the same as notepad.exe and other apps with windows that are
mostly just a basic text box).

I guess with my video card, the hardware acceleration actually makes
things slower. I haven't checked yet, but I'm guessing (hoping) there
will be an easy way for me to tell Windows (.NET or WPF) not to use
acceleration for my app, without the user having to disable it for the
entire system. At least if this is possible, I can give the user an
easy way to enable/disable for my app (maybe even try to some
autodetect if I need to, to figure out which mode is faster).
 
B

Ben Voigt [C++ MVP]

Display properties just says "Generic VGA Driver" on the Vista PC, and
XP just says "UniChrome Pro IGP", which probably isn't very helpful,
but even if I could open the cases right now I'm not sure I could tell
exactly what cards they are anyway.

not_a_commie correctly identified your problem. WPF uses DirectX, until you
install the right Vista driver it will remain slow, and the Unichrome IGP
just is going to be slow no matter what, it's a very underpowered graphics
solution.
 
E

eselk2003

not_a_commie correctly identified your problem.  WPF uses DirectX, until you
install the right Vista driver it will remain slow, and the Unichrome IGP
just is going to be slow no matter what, it's a very underpowered graphics
solution.

Good to know, and I guess I've never used anything that used graphics
acceleration before. In my case I'm writing an app that I want to
work well even if the graphics card is low-end, and I figured out how
to disable acceleration on a per-window basis, so all is good now.
The app I'm writing does use some gradients and shadows, but not to
the extent that a low-end graphics card without using acceleration
can't handle them decently (I've written similar apps in generic
Win32, and they work fine, just turns out that WPF with acceleration
was extra slow, I guess because the hardware is worse than software
rendering).

On a side note, which I just think is really interesting and that is
the only reason I'm even mentioning it... I noticed that I had made my
test app as a VB app by mistake (noticed when I tried to add the first
line of code and it created a VB file instead of CS). Anyway, I
created the same app as a C# project, and now it is fast even with
hardware acceleration enabled. I even went back and rebuilt the VB
app again, and it was still slow. I'm sure people here will be quick
to point out that VB is "slower", but wow, that really surprised me
seeing as how I hadn't written any code at all (just the XAML file).

At first I thought maybe the C# version wasn't using acceleration for
some other reason, but then I tried disabling hardware acceleration
and I didn't notice some minor differences (context menu fade-in/out)
that make me think the C# version is still using acceleration and is
just faster for whatever obscure reason.

No doubt all of the slowness for whatever minor variances is still all
related to poor video card and/or driver... good to know that an easy
option is just to disable hardware acceleration (or let user toggle it
for best results for their setup)... can even be per-window. I found
the code here:

http://blogs.msdn.com/jgoldb/default.aspx?p=2

Search for "RenderMode.SoftwareOnly".
 
M

Michael C

Good to know, and I guess I've never used anything that used graphics
acceleration before.

I think you're missing the point. Every windows app uses hardware
acceleration. For example, if an app calls the FillRectangle API then
windows will send a message to the video card saying "draw a rectangle from
a to b". It will not send a message to the card telling it to draw each
pixel (unless the card is really old or acceleration is turned off).
However, WPF uses directX which is the API commonly used for games. This is
a whole different ball game and it sounds like your card is very slow with
DirectX. By turning off hardware acceleration it sounds like your turning
off DirectX for this app.
In my case I'm writing an app that I want to
work well even if the graphics card is low-end,

I might suggest that WPF is not the best option then.
I'm sure people here will be quick
to point out that VB is "slower", but wow, that really surprised me
seeing as how I hadn't written any code at all (just the XAML file).

That is odd, are you sure this wasn't a mistake, say if the hardware
acceleration was already turned off?

Michael
 
F

Frans Bouma [C# MVP]

Michael said:
I think you're missing the point. Every windows app uses hardware
acceleration. For example, if an app calls the FillRectangle API then
windows will send a message to the video card saying "draw a rectangle from
a to b". It will not send a message to the card telling it to draw each
pixel (unless the card is really old or acceleration is turned off).

It's still slow, as the pixels have to be transfered back to
main-memory to be merged with the DC pixels, otherwise windows can't
restore window contents when you drag a window away in front of another
window. Also, it depends on the driver if a call is accelerated.
However, WPF uses directX which is the API commonly used for games. This is
a whole different ball game and it sounds like your card is very slow with
DirectX. By turning off hardware acceleration it sounds like your turning
off DirectX for this app.

Still, software rendering should be fast enough, unless the CPU is also
dogslow.

FB
--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top