linq2db/linq2db — pull request #48 by mstijak (2013-11-16 13:40:06+00:00)
Title: Startup performance optimization

Hi,

I encountered a strange startup delay with linq2db for some type of queres. If run first

```
var u = ctx.Users.OrderBy(a=>a.Email).FirstOrDefault();
```
would take 1100 ms and
```
var u = ctx.Users.FirstOrDefault();
```
would take only 300ms.

Profiling showed that the difference is caused by compiling members dictionary for mapping complex expressions such as string operations and convert functions, sql functions. These functions are not used in most queries, so I added few changes to delay creating of this dictionary until it's actually required. Result is that both queries now finish in about the same time. Requirement check is based on the namespace of the declaring member, and that should be reviewed by a more experienced developer.

Further optimization would be to split LoadMembers method to multiple methods and load the dictionary part by part based on the declaring type or member name. In that case performance penalty would be divided and tied to queries that actually use complex expressions of that type, but I could not figure out elegant way to implement this. I'm sure you'll know better.

Best regards,
Marko