InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Indexes for LINQ

Posted by Jonathan Allen on Apr 30, 2007

Sections
Development,
Architecture & Design
Topics
Performance & Scalability ,
.NET
Tags
LINQ

When a LINQ expression directly targets a database, the DLINQ provider has full access to the database's indexes. But LINQ is not only about databases, it can also target XML or even simple object collections. For larger queries, the lack of indexing may become an issue.

In order to address the issue, Aaron Erickson has created a product called Index for Objects or i4o. This project, which is open source, is downright trivial to use. One merely has to add an Indexable attribute to properties that should be indexed. When the objects are subsequently placed in an IndexableCollection, the indexes are automatically generated.

The magic occurs at runtime when calls to the Where and Join extension methods are made. i4o evaluates the expression tree and, if appropriate, replaces the for-each loops with an index lookup.

This technique may end up only being applicable when using very large, in memory object collections. In tests against collections of 1 million objects, i4o resulted in speed improvements of roughly two orders of magnitude.

Being a new project, there are still pending issues. Some are trivial and will be done soon, like adding support for removing objects from collections or supporting BindingList. The harder ones include how to handle updates to objects in an indexed collection. The objects do not 'know' they are in a collection, adding support for INotifyPropertyChanged to every indexed class is tedious, and it probably is not possible to use some sort of Aspect Orientated Programming technique to inject the necessary event hooks.

The project in binary and source code format can be downloaded from CodePlex. For more information about i4o, or to make suggestions for future enhancements, you can read Aaron Erickson's blog.

No comments

Watch Thread Reply

Educational Content

Jesper Boeg on Priming Kanban

In this interview, Jesper Boeg, author of the new InfoQ book – Priming Kanban, discusses the keys to using Kanban effectively, and how to get started if you are currently using other approaches.

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.