inline function -- help needed

We are a small company focusing on XmL processing, our XML processor is called VTD-XML and we did a port from Java to C# using JLCA 3.0 so the same code for Java and C#... however performance of C# is only similar to Java's client hotspot jVM, so we did some profiling and it seems that Java's server JVM does very agressive inlining on a couple of frequently called functions, whereas C#'s VM doesn't do, so the result is there is a 20%~25% drop in C#'s VTD-XML performance... Can someone point us to good reference on how to optimize C# code performance to explicit inlining... or we appreciate any suggestions!!!

http://vtd-xml.sf.net is where to get our code in C/C# and Java




Answer this question

inline function -- help needed

  • Ty Anderson

    1) As I remember, Intel CPU do branch prediction and TRUE block in IF operator will preexecute in CPU while condition computed. This mean that better write this code:

    if (Enclosing_Instance.offset < Enclosing_Instance.endOffset)
    {
    method body here
    }
    else throw...


    2) Another point of interest is this XMLDoc[] indexer and handleUTF8() method - what is inside them Perhaps they can be optimized. Does handleUTF8() called often What is inside


    3) such strange pattern - using property to read something. Property means I can read things many times and they do not changed until I made some other call. Here I can read this property twice and get different result... not good architectural decision. This should be method instead or property can return current char and some Next() method will advance to the next char.
    Another possible interesting idea - make iterator from
    UTF8Reader. But this is really depend on how you use this class.


  • David Robert

    The code is shown below, the bottleneck is obviously the Char getter, we have optimized the C version before and as long as we put inline around the getChar() the performance jumped 20%, in C# we feel helpless ...

    internal class UTF8Reader : IReader
    {
    private void InitBlock(VTDGen enclosingInstance)
    {
    this.enclosingInstance = enclosingInstance;
    }
    private VTDGen enclosingInstance;
    public int Char
    {
    get
    {
    if (Enclosing_Instance.offset >= Enclosing_Instance.endOffset)
    throw new EOFException("permature EOF reached, XML document incomplete");
    int temp = Enclosing_Instance.XMLDoc[Enclosing_Instance.offset];
    //int a = 0, c = 0, d = 0, val = 0;
    if (temp <127)
    {
    Enclosing_Instance.offset++;
    return temp;
    }
    return handleUTF8(temp);
    }

    }



  • SMohan

    Hi!

    I don't remember that C# have explicit inlining, can you post some code that works ugly


  • inline function -- help needed