Archive for the ‘software design’ Category

Optimizing the search beast

August 22, 2010 Leave a comment

One of the projects I’m working on is a product catalog update service. Basically, it provides a couple of web services that updates the database following some rules. One of the services receives a review and upgrades the metadata according an analysis of the text. When I came to the project, all was implemented but it was slow, so my work was to help optimizing the code. I love when projects follows the “desing first, optimize later” idea.

The model have a Searcher class that looks for a series of terms in the text and returns the ones contained in it. The performance problem begun when we started using a real database containing 50000 terms. Let’s assume that the search algorythm is really fast.

Since the text we received has something like 1000 words, the first approach we thought was to create a text with the 50000 terms and to look the 1000 words in it. It didn’t work, because we have to look for terms, not words, and terms could have spaces, so it’s impossible to know where to cut the text.

Well, analyizing the stored terms we realized that several terms were similar or, what is more interesting, started with the same word. So we indexed the terms by first word and look for those words first. Once we know which words exist in the text, we could look for the terms starting with those words only and reduce the amount of terms to find.

Well, the amount of “first words” was ~3500, and it was solved really fast. Finally, the new code performed 25 times faster that the old one :). I was really impressed.


Why they don’t want us to do unit testing over Sharepoint?

August 10, 2010 2 comments

I don’t understand what’s happening. Besides the aberrant idea of havig such a monster without a way to mock it by design (I know, TypeMock supports Sharepoint isolation, but it’s not by design and it’s not free), they just disabled the possibility of doing unit tests over it.

Basically, it seems like Sharepoint runs in .NET framework 3.5 and you can’t change the target of a Visual Studio Test Project to 3.5, it has to be 4.0. So, you are not able to test it.

One more time, I’m moving to NUnit.

MirrorMirror: Working on the generics API

June 12, 2010 2 comments

Yesterday I finished the basic invokation API for MirrorMirror. Now I want it to start supporting generic methods. Since the current API uses params object[] for the parameters, I don’t know how to add the type parameters to that. I want to avoid the usage of generics in the API, because several times you will be dealing with internal types, so you can’t add them as a type parameter.

One idea I have is to change the current, simple API:

var result = object.Invoke("Method", arg1, arg2);


var result = object.Member("Method").Invoke(arg1, arg2);

so I can add method to that chain to support generics:

var result = object.Member("Method").Generic( type1, type2).Invoke(arg1, arg2);

Following this schema, I can always give support to the first API, but it will only work for non generic methods.
Also I would like to add support to generic types inference, so if you have a method with this signature:

private string MyGenericMethod<T1,T2>( T1 a, T2 b)

you can call it without specify the type parameters.

I will be working on this in the following days and will post the final thoughts.