mfp's two cents

...on Dynamics AX Development!

  • mfp's two cents

    The compare tool–and running X++ code as IL


    Running X++ as IL has some huge performance benefits, but you have to be careful. Here is a write up of the changes we went through for the code compare tool in AX 2012 to increase its performance and reduce some IL side effects.

    In Dynamics AX 2012 the compare tool has been through two significant changes to improve performance.

    New algorithm

    The first change was a re-implementation of the algorithm. In AX 2009 (and previous) the algorithm was “home-grown” – in AX 2012 it was changed to use the Longest Common Subsequence algorithm. For texts that were nearly identical this yielded little improvements – but for vastly different texts it became significant. To measure the performance improvement a “typical” text was defined as a text where 10% of all lines contained random text. The new algorithm (orange) could compare two typical texts each with 1100 lines in 10 seconds – the original algorithm (red) could “only” handle 650 lines in 10 seconds.

    Running as IL

    As the algorithm is pure CPU extensive– there is no database involvement- it could benefit significantly by running the code as IL. Switching over to run X++ code as IL is quiet simple in X++. By running the code as IL we can compare 4300 lines in 10 seconds. (green).

    To change the compare code to run as IL, here is what we had to do:

    1. Change the SysCompareText class to run on server tier.
    2. Create a static method that returns a container with results and takes a container as input:

      server static container runCIL(container _inputContainer)
          // Simple variable names used to make correctness obvious.
          str s1, s2;
          boolean b1, b2, b3, b4, b5;

          // Extract parameters from container
          [s1, s2, b1, b2, b3, b4, b5] = _inputContainer;

          // Pass parameters to the compare engine
          return SysCompareText::runInternal(s1, s2, b1, b2, b3, b4, b5);
    3. Call the static method via the runClassMethodIL() API

      XppILExecutePermission perm =

      new XppILExecutePermission();
      return runClassMethodIL(classStr(SysCompareText), staticMethodStr(SysCompareText, runCIL),
      [_text1, _text2, _caseSensitive, _suppressWhiteSpace, _lineNumbers, _singleLine, _alternateLines]);

    The pitfalls

    1. The generated code may not be what you expect.
      The compare algorithm uses a 2-dimensional array. In X++ that was implemented as an int[] (the offset for the indexer was calculated as x+y*width). However; the resulting CLR code uses an Dictionary<int, int> – which consumes 8x as much memory as an System.Int32[] array. This extensive memory consumption could cause AX to run out of memory, when comparing large files – e.g. comparing two 10,000 lines files would consume >3GB memory. The performance of System.Int32[] should also be better, so it was decided to change the int[] to System.Int32[,] and the benchmark was run again.  Much to my surprise the performance decreased (purple). After a while of looking at IL disassembly the reason was clear. The only way to access the contents of an CLR array in X++ is via the get_Item() method, which is a “slow” virtual method call. If just the X++ compiler converted an int[] to a System.Int32[] instead of Dictionary<int,int> then the lightning fast IL array  indexers could be used (and a factor >30x gained.) Yet, it was decided to use the System.Int32[,] array due to the lower memory consumption – even though it was somewhat slower.
    2. The user may disable IL
      If the user deselects “Execute business operations in CIL” under Tools | Options, then the code will execute as regular “slow” pcode. And in the compare case it will run even slower, as we decided to explicitly use System.Int32[,] instead of int[]. This causes a lot of “slow” interop calls into CLR. (blue)


    Compare benchmark


    By changing to a better algorithm and running the compare algorithm as IL, we have increased the size of texts that can be compared in 10 seconds from 650 lines to 3400 lines – a factor of 5. For small texts the difference is insignificant – the larger the text, the larger the gain.  However; if the user disables IL ,then gain from running IL is gone, and a penalty is paid for the IL specific optimizations implemented. In this case it was an optimization to reduce memory consumption.

  • mfp's two cents

    Microsoft Dynamics AX 2012 Development Cookbook


    A new AX development book has just been published. It is an AX 2012 version of Mindaugas Pocius’ development cookbook for AX 2009.

    I’m looking forward to reading this new book and writing a review.

    You can download an eBook version of the book today, or order an hard copy here.

  • mfp's two cents

    TechTalk @ MDCC : Project Roslyn - Compilers and Services for the Masses by Brian Rasmussen


    If you are in the neighborhood and can spare a morning,  you are most welcome at Microsoft Developer Center Copenhagen for a TechTalk by Brian Rasmussen. It is free – but remember to sign up.


    The goal of the Roslyn project is not only to deliver the next generation C# and Visual Basic compilers and language services. Roslyn also provides a rich set of APIs for interacting with the entire compiler pipeline and data model. The Roslyn APIs make parsing source code, querying semantic information, analyzing data and control flows as well as scripting easy. In this talk we look at several examples of how to use the APIs to enhance tools and applications.

    About Brian Rasmussen

    Brian is a Senior SDET at Microsoft working on the next generation C# and Visual Basic language services in Roslyn. Before joining Microsoft Brian was a Microsoft MVP for Visual C# for four years. Brian is blogging on the C# FAQ ( and can be found on Twitter (@kodehoved).

    When:             May 24, 2012 at 09.30 – 10.30

    Where:            Microsoft Development Center Copenhagen, Frydenlunds Alle 6, 2950 Vedbaek

    Sign up:          Here

  • mfp's two cents

    An AX first

    image I just had a first experience with AX. After being a developer on the product for most of my professional career, I was suddenly experiencing AX from a new perspective: The end user’s. Microsoft’s internal expense management system is now powered by Microsoft Dynamics AX 2012, and I had an expense to file.

    Filing my report took only a few minutes, and the experience was familiar to me. It didn’t require any training and the tool was even integrated with AMEX, so I could easily link my expense to the charge on my credit card. The UI was familiar as as I’m used to working with Share Point, ribbons and, of course, Dynamics AX. The experience offers a vast improvement over the old system, which was Excel based, with ever changing templates, required stapling receipts on to paper and printing confirmations. I now feel a little prouder in my daily work.

    To learn more about the Microsoft Dynamics AX 2012 expense management system internally at Microsoft go here.

    In case you want to know, I was expensing the purchase of Pavel Hruby’s book: Model-Drive Design Using Business Patterns.

  • mfp's two cents

    Houston, I have a problem


    Convergence 2012 is over. I didn’t attend. What did I miss? Probably a whole lot – based on all the traffic on Twitter and my past Convergence experiences. Luckily Microsoft has created a Virtual Convergence where attendees can see all recorded sessions on-demand. But even better: Virtual Conference is also for me – even though I didn’t attend the conference. I can stream the keynotes and the general sessions – I’ve already enjoyed Kirill Tatarinov’s keynote and Sri Srinivasan’s general session on Microsoft Dynamics AX 2012. Next time I’ll be sure to go.


  • mfp's two cents

    Dynamics AX 2012 for Retail Virtual Launch Event


    Register for the Microsoft Dynamics AX 2012 for Retail Virtual Launch Event on February 1st, 2012 at 9:00 a.m. Pacific Time (US)

    Microsoft leaders, customers, and retail industry experts will talk about what it means to be a Dynamic Retailer in today’s retail environment while providing a first-look at the powerful retail capabilities being introduced as part of Microsoft Dynamics AX 2012.

    Register now.


  • mfp's two cents

    Dynamics AX 2012–Data upgrade best practices


    A new white paper is available. The white paper includes many performance optimizations we’ve found through customer upgrades. It should benefit anyone who’s considering an upgrade from previous versions of AX to AX 2012.

    You can download the white paper here:

  • mfp's two cents

    Inside Microsoft Dynamics AX 2012


    The pile of AX books will grow this year. I’m pleased to announce that work on the 3rd Inside book from Microsoft Press has commenced. Not surprisingly the book’s title will be “Inside Microsoft Dynamics AX 2012”. The book should hit the shelves late this year.

    I’m going to spend quite some time in Microsoft Word over the next few months.




  • mfp's two cents

    2011 going on 2012


    The year 2011 has been an amazing year for AX.

    Most remarkably, of course, has been the launch of Microsoft Dynamics AX 2012. Being an engineer, on a team working on a product for several years before finally making it public available, is in all honesty a mixed experience. On one hand you are the “proud parent“ boasting of everything that was accomplished – on the other hand you know it marks the end of a long journey with a great team. The only comforts are how well “your little one” has been received, and that you know a new journey is awaiting just around the corner.

    In 2011 we’ve also been treated to no less than two Technical Conferences on AX. After what feels like a decade - they are finally back. For me personally, I’d been missing these opportunities to talk to peer X++ developers and I fully enjoyed every second I spent in Redmond in January and in Nice in November. I also must say “Thank you” for the overwhelming feedback I’ve received from my presentations. It is much appreciated.

    Let us keep the momentum next year - I believe AX is ready for 2012!

    Enjoy the holidays, and happy new year!


    I think I’m going to have a game of Scrabble with my kids without thinking too much about work Smiley

  • mfp's two cents

    Deploying AX 2012 Customizations


    Models, XPOs, Model store files, signing, uninstall, metadata, compilation, IL, move between environments – are you on top of them all?

    If not, here is a very useful whitepaper:


Page 6 of 20 (195 items) «45678»