Snikt! Yet another OR-Mapper
Our new product is selling like crazy
I love Microsoft, especially when it comes to Visual Studio. I would do J2E if it supports. Years back, the glory days of one of the companies I worked, decided to migrate one of the products, super-duper banking app to windows platform, to .NET ofcoz. There were few day-end routines we wrote which processes transactions to accrued interests but not more than 15 of those. We noticed there is a significant performance leak, that it took almost half-a-day to finish off, and was absolutely unacceptable for the few thousand accounts the bank had.
It wasnât a complicated solution, yet, the Memory and the CPU were hitting nearly 100% on the app server. There were stored command used to perform queries, .NET reflections used to late bound routines, but the leaks had nothing to do with these designs of the code.
The frameworks that made our lives rapid!
Yes, we have made few mistakes here and there, and then there is Typed Datasets used as the OR-mapper in the data-tier which made our rapid development run off the roof â that was a +1. When we are digging deeper into the core of the code, debugger consumed considerable time just to instantiate the datasets. It would have been acceptable but doing this for 100s of thousands was a big cost for us. There werenât hand full of ORMs at that time, and the ADO.NET Typed Datasets was the thingy. We were not in a position to drop all the Typed Datasets to old-school way of mapping query results to business objects. A pragmatic approach was to use the core business object, which is the Account model only on the day-end processes as a proof of concept.
Few nights with cheesy pizza and beer, my colleague Buddhi Pathirane and I managed to run the day-end routines again with old-school mappings. SHAZAM! the processes did not even take more than couple of hours to complete. In general, most of the code we wrote had to deal with stored commands, mapping query results to domain models, than the business logic. It was the fastest we could do in terms of execution, but sadly there were new bugs introduced, then there is this code that we had to write and it made our grown up developers cry.
That omnishambolic moment!
One of those days, another critical feature was to migrate all the Swedish vehicle details to a SQL server database. Operations were mostly upserts for 7-10tables and the process took nearly 9hours for 4million records. This time, it was on LINQ-to-SQL and there is nothing much we can do to hint the DataContext to optimize queries. So we decided to write our own T-SQL commands. Itâs something we are all quite familiar with.
Choosing Entity Framework over LINQ-to-SQL had many benefits. The business components need not to know what data model I use. So, we used Entity Frameworkâs promising Code First T4 template to split the Context from the domain model. It was the unicorn when we decided to use in almost all the projects in that company. Fellow developers loved it but the major issue is that it is 2-3 times slower, or even worst in some cases. So, for many scenarios I had to write my own queries, and so did everyone else.
This out-performed in most cases but sometimes the SQL generated by the query parser is similar to the ordinary SQL we write. This led us to another clue: performance leaks were not along with the queries designed by the ORMs. Both frameworksâ mapping logic was not fast enough for this matter.
How many times do I have to fall?
We were querying and mapping results to the business objects, so we used in-line SQL queries and stored commands every time there is a significant performance leak which is quite normal for us. Typed Datasets, LINQ-to-SQL, and Entity Framework have its positives but thatâs what it has been hyper promoted by the owners and the followers, for any other full blown ORM for that matters.
All I need is an ORM that suites my data-tier which can map SQL query results to business objects, not their associations and so on. It is quite straightforward so I tried writing by my own. Hereâs how the first version looked like. It would be a crazy idea to replace the entire ORM, so my intention was to tweak some leaks side-by-side with this mapper wherever applicable. I also thought to push an open-source version with few more enhancements. Hereâs the GitHub repo to fork.
More resources:
Snikt! source code to fork
Comic credits to Dilbert.com
















