设为首页 加入收藏

TOP

BLToolkitLinq-provider(十三)
2015-11-21 01:53:40 来源: 作者: 【 】 浏览:5
Tags:BLToolkitLinq-provider
].[CustomerID] = [o].[CustomerID] AND [o].[ShipRegion] = 'SP' ) as [c1], ( SELECT Count(*) FROM [Orders] [o1] WHERE [c].[CustomerID] = [o1].[CustomerID] AND [o1].[ShipRegion] = 'NM' ) as [c2] FROM [Customers] [c]

Performance

Performance issues in Linq

The ability to create Linq providers, broadcasting Linq to SQL queries and other formats is undoubtedly the greatest achievement of the ruling in the technology industry. But what is the charge for such achievements? The article Building a LINQ Provider briefly describes the process of creating a service provider like Linq To SQL. In addition, this article describes the path that passes Linq expression of the structure created by the compiler, before converting it into a SQL or another format.

In contrast to the normal code, the compiler does not produce on the basis of Linq expressions executable code, but instead includes a code for forming a special structure that describes the original Linq expression, the so-called Expression Tree. Further, this structure somehow passed Linq provider, which in turn parses it and converts to the desired format. All this is done at runtime. Ie calling a method with Linq query, we call the code that each time first creates Expression Tree, then passes it Linq provider, which in turn parses it using complex and resource-intensive algorithm.

You could cache the results of parsing, but apart from the fact that every time we are dealing with a newly created structure, and it can even be different. Differences can arise, firstly, because of the possibility to create such a structure by parts, such as in the following example:

var query =
    from e in db.Employee
    select e;

if (a > 0)
{
    query =
        from e in query
        where e.EmployeeID > id
        select e;
}

Second, the values ??of transmitted parameters, such as the parameter id in the example above, are incorporated directly into Expression Tree, making this structure depends on the values ??of the parameters.

As a result, we have to parse the Linq queries each time. It is clear that this approach is low speed of Linq queries we guarantee.

Turning to the test site ORMBattle.net, for example, to this chart, you can easily verify the validity of this assumption. Below is a table with the numbers from the chart that we will be interested.

?

BLT

EF

IS

DO

L2S

SQL

Unit

LINQ Query

8749

450

933

1559

835

n/a

queries/s

Compiled LINQ Query

13222

6501

2395

8046

9114

n/a

queries/s

Native Query

17187

9728

8465

10335

n/a

18645

queries/s

Here, horizontal:

Query LINQ - Linq queries is implemented by different providers. Linq Query Compiled - compiled Linq queries. On them will be discussed below. Query Native - database queries without using Linq.

Vertical lists various Linq providers penultimate column - pure SQL, the latter - a unit of measure (RPS). The highest attainable standard of bold - is the SQL / Native Query.

Compared with the figures of the reference line LINQ Query you can see that some providers slowing client code using Linq queries may be dozens! times.

As BLToolkit struggles with the situation, provided that the parsing algorithm Expression Tree in BLToolkit no less complex and resource-intensive? We remember that the cache Expression Tree is impossible, but simple logic says that if you really want, you can.

Stratagem is as follows. For each request takes a cache BLToolkit already processed trees and compares them with the original. When comparing the trees are not captured fragments

首页 上一页 10 11 12 13 下一页 尾页 13/13/13
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Mysql Master Slave Config 下一篇BI-SSAS简介篇

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: