The World’s Leading Microsoft .NET Magazine
   
 
The .NET Addict's Blog

My Top Tags

                                                           

My RSS Feeds








I heart FeedBurner

Latest Diggs - Programming

Computers Blogs - Blog Top Sites

Site Hits

Total: 4,908,322
since: 19 Jan 2005

Smart, Deep Property Notifications in CLINQ v2.0

posted Tue 07 Oct 08

Before I get into a description of the new feature, I'll walk you through the problem that it solves. In case you didn't know, CLINQ is a library that allows your LINQ queries to remain "alive" (or "Continuous") after their initial creation. This means that you can create a query like this:

myTransactions = from tx in allTransactions
    where tx.DestinationCode == "05020"
    orderby tx.ProcessDate descending
    select tx;

and your result set will continue to automatically update itself as changes occur in the source collection (including changes that occur to items already in the source collection). This is the heart of the functionality that CLINQ provides. However, in v1.x there is a performance problem here that is actually rather large.

Let's say that, in the preceding query, the Transaction class has 30 properties. Further, let's assume that 10 or 15 of those properties are changing rapidly, perhaps hundreds of times per second. These properties change as the transaction flows through the system and is poked and prodded by various operating workflows and other monitoring processes. The problem here is that these 10 or 15 property changes really don't matter for our original query.. the DestinationCode property rarely changes, if at all. 

Under CLINQ v1.x, even if we don't care about those other property changes, we could be looking at re-evaluating the query up to 1500 times PER SECOND because the query is re-evaluated for each property change it detects on a source object, and we've got hundreds of irrelevant property changes occurring on 10-15 different properties per second. Multiply that inefficiency out by the number of items in your source set, and you've got a huge problem. You might be thinking, "That doesn't bother me, my data doesn't change that rapidly". Well, your data could change that rapidly in the future. Also, if you're working with financial data, 1500 changes per second is a lowball estimate and you could be looking at far more than that.

This is where CLINQ v2.0 comes in. In CLINQ v2.0, every lambda you pass to the CLINQ extensions is now treated as an Expression. As a result, we can now troll through the entire expression tree, parse out the list of monitorable properties you used in the expression, and only listen for when those specific properties change.

As a result, you could have 1500 property changes per second, but CLINQ v2.0 will remain completely idle until one of those property changes modifies a property that could impact your result set. It will NOT respond to property changes that will have no impact on your result set. This is what we're calling Smart Property Notification. Using Smart Notification, we are seeing exponential performance increases in some circumstances.

Once we were able to do Smart notification using Expression trees, it was a logical next step to allow DEEP notification. This means that you can use nested property references in your CLINQ expressions and CLINQ will actually walk the DEEP property access tree, and only listen to changes on the bottom-most object, and only to the properties on that object that are meaningful.

This means that we can re-write the above query to handle a more robust underlying business object model:

myTransactions = from tx in allTransactions
    where tx.Destination.DestinationCode == "05020"
    orderby tx.ProcessRecord.ProcessDate descending
    select tx;

Note how the preceding query is actually traversing a hierarchical object graph to get the job done. If the DestinationCode property on the Destination object (which is a property) changes, or if the ProcessDate property on the ProcessRecord property object changes, then CLINQ will perform a re-evaluation. Otherwise, CLINQ will remain completely idle.

None of this would be implemented without the awesome contributions of people like Andy Kutruff and without the open source concepts that are being fostered by sites like CodePlex.

You can grab the latest source code to CLINQ 2 (or preferably wait for the actual release) at CodePlex's CLINQ site .

tags:          

links: digg this    del.icio.us    technorati    reddit

AddThis Social Bookmark Button




1. Jordan Vinarub left...
Tue 07 Oct 08 2:11 pm

This is the kind of stuff MS should have put in the .NET Framework. Nice job!


Tag Related Posts

Smart, Deep Property Notifications in CLINQ v2.0

Tue 07 Oct 08 1:15 P GMT-05
tags:          

Microsoft's Lofty Direction

Sun 05 Oct 08 2:30 P GMT-05

MobileMe vs. Live Mesh Throwdown - Round 1

Wed 16 Jul 08 10:33 A GMT-05

Building Model Classes in C# and Cocoa

Sun 15 Jun 08 3:13 P GMT-05
tags:            

CLINQ v1.1.0.0 Released!

Fri 02 May 08 5:38 P GMT-05
tags:          

One Framework to Rule them All

Mon 25 Feb 08 6:49 P GMT-05

CLINQ v1 Demo - Network Message Filtering

Wed 09 Jan 08 7:47 P GMT-05
tags:        

Continuous LINQ v1.0.0.0 Released

Tue 08 Jan 08 4:53 P GMT-05

LINQ to REST - A much better name for Astoria

Tue 11 Dec 07 1:23 P GMT-05
tags:        

Unexpected and Unsafe behavior in LINQ

Wed 14 Nov 07 8:09 P GMT-05
tags:    

Building a Ledger Style for WPF Grids

Tue 21 Aug 07 3:30 P GMT-05
tags:    

Continuous LINQ - Can I write games with it?

Mon 13 Aug 07 3:09 P GMT-05
tags:        

Continuous LINQ

Mon 06 Aug 07 1:21 P GMT-05
tags:    

Dynamic, Observable LINQ Views

Tue 31 Jul 07 1:21 A GMT-05
tags:        

The dreaded language bleed-over has begun

Tue 19 Jun 07 6:23 P GMT-05
tags:        

Installing Orcas Beta 1 - VMware Style

Mon 23 Apr 07 12:16 P GMT-05

My Little Pony .NET Unleashed 2007

Fri 30 Mar 07 1:59 P GMT-05

Authorness

Thu 15 Mar 07 1:44 P GMT-05

Visual Studio "Orcas" - March CTP is Available

Wed 28 Feb 07 12:28 P GMT-05
tags:            

Objective-C Categories vs C# 3.5 Language Extensions

Mon 26 Feb 07 1:05 P GMT-05
tags:                

Localizing a WPF Application

Tue 22 Aug 06 11:39 A GMT-05
tags:            

Is Windows Workflow Foundation Too Complex?

Fri 18 Aug 06 12:15 P GMT-05

DLinq vs the ADO.NET Entity Framework

Fri 23 Jun 06 4:01 P GMT-05

WPF/XAML and LINQ - A match made in heaven

Tue 06 Jun 06 11:32 A GMT-05
tags:                  

Language Extensions in C# 3.0

Wed 31 May 06 2:17 P GMT-05

Lambda Lambda Lambda

Sun 21 May 06 1:01 A GMT-05

The Adventures of LINQ (Not Zelda)

Fri 19 May 06 11:21 P GMT-05
tags: