rdavin

Sometimes, it's the small things that matter

Blog Post created by rdavin Employee on Nov 7, 2012

Once again I take the opportunity to share when I trip up.  For the past 3+ years, I have been doing AF development and frequently need to see if an AFAttribute uses the PI Point data reference.  The need is so common that I have a little extension method that is short, simple, and sweet:

 

    public static bool UsesPIPointDR(this AFAttribute attribute)
    {
        return (attribute.DataReference != null) && (attribute.DataReference.Name == "PI Point");
    }

 

 

Maybe not so sweet.  Would you believe that tiny bit of code is actually quite sluggish, and therefore not so sweet?  Not that this is a fault of OSIsoft.  Rather, my simple little extension method is written poorly.  The much faster way to achieve the desired check is:

 

    public static bool UsesPIPointDR(this AFAttribute attribute)
    {
        return (attribute.DataReferencePlugin != null) && (attribute.DataReferencePlugIn.Name == "PI Point");
    }

 

 

It's a small, subtle difference using DataReferencePlugIn instead of DataReference but it makes a big difference with big numbers.  Let's take a look for a database remote to me going across a very slow WAN.  This database has 353 elements, well over 100,000 attributes, with 18,743 of those attributes using the PI Point data reference.  We may have closer to 200,000 attributes and we go many generations deep (up to 6).  I wrote a subroutine to load all elements, and then crawl over all attributes looking for those that are PI Points.  For today's topic, the only timing I worry about is just crawling over all attributes looking for PI Points.

 

Running the first method against DataReference took 11,542 milliseconds.  Did I mention that I have a slow WAN?  Okay, so running the second method against DataReferencePlugIn took 247 milliseconds!  It ran so bleeping fast that I assumed it was an error.  The error was that I've been using the wrong method all these years.

Outcomes