Tuesday, February 22, 2011

NaroCAD Startup Time And Lazy Loading

NaroCAD historically was used to use SCSF and as it was removed for some time, NaroCAD improves start time from like (I will use timing from my machine) 7-8 seconds to 4 seconds. Most of this time was because of JIT of SCSF and SCSF related logic.
As of today the startup time is splitted like this: library startup (.Net, DirectX subset used by WPF, OpenCascade startup, browser control that is used both on Tips window and on Help view), JIT (still, but at a smaller margin), layouting (Ribbon control will layout all buttons to fit right, all menu items and so on), NaroCAD framework logic and some Boo evaluation code.
So as for now on my machine (which is an i5M CPU class laptop) is around 3 seconds and I will explain what was changed in mostly the last 2 months, from when SCSF was removed and how JIT time was also greatly removed.
When we register things in NaroCAD (like actions, buttons) we always hit constructors. And this constructors are compiled with everything is in them. So, the logic that was in the past, regarding them was moved to an external method, that can be overriden named OnRegister. This will be called lazily as needed, so you will likely you will not see that an action will need a list of inputs to be setup. Another thing is that most actions will inherit mostly two classes (ModifierContainer or DrawingLiveShape) making precompiling to happen just once.
Another small issue was that layouting of all tabs take around 0.7 seconds, so tabs are also layouted from first time when you activate them. This will add just 0.2 seconds on average (for first time) when you will switch tab, but is much better if you will start often NaroCAD (hopefully not for crashing reasons).
Another section that was seen in profiling, and was made in 1.5.7 timeframe (so you get this even without nightly builds) is that Boo expression evaluator will be used in any instance using an interpreter. This will mean that your expresions if are like loops, they will likely execute slower (yet, external methods are executed through a compiler). To run as an interpreter, makes the logic of the code much simpler from Boo parsing and executing side and will likely speedup 3x in most cases.
At the end, regular poly tool was compiled at NaroCAD startup, but today is compiled just first time when is used.
Why I wrote this post? Mostly to know that we do keep an eye on how NaroCAD works both outside (we get on average fewer errors than in previous releases as bug reports even as download count goes up) and from inside.
Also, I wanted to you to know how and why "NaroCAD is slow": WPF is like starting a small DirectX game, and similarly when we start OpenCascade libraries (that load OpenGL libraries), Internet Explorer control, Ribbon to do layouting, and so on, at the end you will get this startup time.
Do you have a specific case when NaroCAD works slow for you? May you share it with us? Use NaroCAD and with your feedback we will make it better.
As an update: sometimes Polar Coordinate setup may lose its values from options and all around bugs were fixed. We use cubic spline "magic number", so if you will draw splines that are placed in corned of a square, the 4 leg spline will approximate a circle as described here. The next nightly may show it to you.

No comments: