CategoryExternal Articles

Creating zillions of objects fast! Don’t “Activate”

Follow me

Joan Vilariño

Senior .NET Developer at Ohpen
Developer for more than 25 years and IT, gadget, mobile and electronics enthusiast working and publishing from Barcelona.
Follow me

Creating objects in .NET or any other language is an easy task, using it’s new() or equivalent keyword, but sometimes things are not that straightforward. There are many times when you don’t even know the type of object you will need to create.

Let’s take for example an entity mapper. It can need to map hundreds of thousands of records from a database, and normally you will use a “Generic Mapper” to create them.

Most people would use the .NET Activator class to do this:

public T Create<T>() {
    return Activator.CreateInstance(typeof(T)) as T;
}

While this is an easy and convenient approach, it’s painfully slow compared to a new() call.

Surfing the internet looking for some ideas, I found this article where you can see a pretty nifty idea to create zillions of objects much, much faster, using Linq expressions, rather than with Activator, that will allow you to do this:

ConstructorInfo ctor = typeof(Created).GetConstructors().First();
ObjectActivator<Created> createdActivator = GetActivator<Created>(ctor);
...
//create an instance:
Created instance = createdActivator (123, "Roger");

http://rogeralsing.com/2008/02/28/linq-expressions-creating-objects/

In this article they show you how to use Linq lambda expressions to create objects at a blazing fast speed, near the new() speed, giving you a good alternative for your mapper classes…

The results are really impressive, as the article shows, for a bulk of 1000000 (yeah, one million) objects:

Activator.CreateInstance: 8.74 sec
Linq Expressions: 0.104 sec

In some time, I’ll try to make a follow-up article for this one, showing you how to make your object factory using this method, but for the time being…

Enjoy it!

Configuration and Optimization of view engines

Follow me

Joan Vilariño

Senior .NET Developer at Ohpen
Developer for more than 25 years and IT, gadget, mobile and electronics enthusiast working and publishing from Barcelona.
Follow me

Mi colleague and former co-worker over the years in many projects, Jose Martínez, has written this great article to start his new blog, about #configuration and #optimization of the different view-rendering engines available in #ASP.NET #MVC.

It’s a very complete and documented article, so you could be punished for not reading it! It’s worth a bit of your time… the only thing, it’s written in spanish, but our buddy Google can lend a hand translating…

http://josemartinez.info/2015/01/14/configuracion-y-optimizacion-de-los-motores-de-vista-view-engines-de-mvc/#comment-4

Algorithms!

Follow me

Joan Vilariño

Senior .NET Developer at Ohpen
Developer for more than 25 years and IT, gadget, mobile and electronics enthusiast working and publishing from Barcelona.
Follow me

I’ve found this #repository at Github containing lots of the most famous #development #algorithms written in #javascript, including sorting, search, graphics, compression, data structures…

Even though you don’t develop in #javascript, it’s worth a read to see the different techniques used, and to have it as reference in case you have to implement any of these in another language.

There are also test clases for #unittesting with #jasmine.

Here is the link to the Github repository sources:

https://github.com/mgechev/javascript-algorithms/tree/master/src

Follow me

Joan Vilariño

Senior .NET Developer at Ohpen
Developer for more than 25 years and IT, gadget, mobile and electronics enthusiast working and publishing from Barcelona.
Follow me

Very complete article demoing a SPA (Single Page Application) using AngujarJS + ASP.NET WebApi.

The project uses common architecture patterns so it’s a good start point if you have never done this before.

Visit this link

Follow me

Joan Vilariño

Senior .NET Developer at Ohpen
Developer for more than 25 years and IT, gadget, mobile and electronics enthusiast working and publishing from Barcelona.
Follow me

New tools for C# 6.0. nameof(identifier) looks very , very useful!

http://www.kunal-chowdhury.com/2014/12/csharp-6-nameof-expression.html

© 2018 My Coding Corner

Theme by Anders NorénUp ↑

%d bloggers like this:
Skip to toolbar