8

I've created a simple application with wpf, and noticed a strange behavior: the Application has two buttons, with unrelated and very simple behaviors. Whenever I launch it, the first click of any of the buttons takes two to three seconds to complete. Only the first click is slow. Subsequent clicks are almost immediate, as expected for their simple behaviour. I've searched google and SO, but nobody seems to be experiencing the same problem.

the details of the application are:

NorthWind db on SQL server 2008;

Linq to SQL auto generated classes;

Customers Table as a DataGrid;

Button 1 OnClick Event: Context.SubmitChanges();

Button 2 Onclick Event alternates a boolean DependencyProperty on the MainWindow class.

As you can see, the setup is very simple. If every single click of the buttons was slow, I would have attributed them to WPF performance issues. What is strange is that whenever I launch it, only the first click responds slowly, and others are normal.

Vinod Kumar Y S
  • 628
  • 3
  • 9
jose
  • 637
  • 6
  • 20
  • The JIT compiler has to compile the bytecode on the first click. It can execute the compiled native code on other clicks because it's been cached in memory. This would make any click after the first one much faster. – Rohan Oct 03 '13 at 13:38
  • I've seen some network operation exhibit this behavior. I initially thought it had to do with hostname lookup, but that should be cached by the OS, but every time the application was run this would happen. You describe it happening with a non-network related operation though. – Steve Oct 03 '13 at 13:49
  • @Rohan I thought about that, but shouldn't the compilation be completed before the application is launched? If not, is there any way to force this behaviour? – jose Oct 03 '13 at 13:50
  • 2
    @jose No, JIT compilers compile code "just in time", hence the name. The compilation into bytecode is completed before the application launch, but not the compilation into native code (this happens during runtime). An optimization of the JIT compiler is that it caches machine code for later use. That might be why your clicks after your first click are faster than your first click. – Rohan Oct 03 '13 at 13:57
  • 1
    Did you run the application in release mode and without VS? – Vyacheslav Volkov Oct 03 '13 at 14:07
  • I had run in release mode, and the slowdown continued. I ran without VS after you asked (hadn't thought about it before), and it runs normally, without the slowdown – jose Oct 03 '13 at 14:11
  • 2
    And I've just found the solution in [this question](http://stackoverflow.com/questions/12885803/wpf-application-stalls-freezes-after-first-interaction-like-button-click?rq=1). I didn't think they were related since the other question talks about every single first interaction. Now I'm not sure if my question is a duplicate or not. – jose Oct 03 '13 at 14:16
  • this related to the Entity Framework context performing some warm-up tasks when you use it for the first time. – Federico Berasategui Oct 03 '13 at 14:48
  • @Highcore I'm not using EF. The problem is actually caused by Gesture Capture in IntelliTrace, as stated in the answer to the question I've linked above. – jose Oct 03 '13 at 15:04

1 Answers1

9

Just to get this question off the unanswered list, here are my findings: this is a known issue with the gesture capture of IntelliTrace. Turning off the gesture capture (Tools>->Options->IntelliTrace->IntelliTrace Events) makes the problem go away completely. More details can be found in this answer

Community
  • 1
  • 1
jose
  • 637
  • 6
  • 20