大数据量表的性能流程文档
我尝试做的事情:
根据数据库中的数据生成报告,然后能够查看和打印它。 (这在 WPF C# 中)
我是如何做到的:(动态地,通过代码)
我的窗口很简单,它只是一个 FlowDocumentPageViewer,里面什么都没有。
- 我从数据库加载数据
- 使用 LINQ 将其全部正确分组
- 初始化一个新的 Flowdocument
- 制作一个表,其中包含RowGroup
- 循环我的 LINQed 数据,并用 TableRows 填充 RowGroup,其中包含具有所需数据的单元格
- 将表添加到 Flowdocument
这几乎可以正常工作,除非记录量达到10k。然后由于某种原因,它只是将我的 CPU 占用到 25%,并且需要 30 分钟。滚动也几乎是不可能的,什么也没有发生,只是完全卡住了。 但是当我得到1k条记录时,需要18秒。如果是 2k,则需要 74 秒。
但是,我不使用表格中单元格的标准方式,我必须为每个单元格创建一个 TextBlock,并将其与 BlockUIContainer 一起使用。但经过一些测试后,它似乎对生成文档没有太大影响。
有人对我应该担心的事情有建议吗?这将是一个很大的帮助,我在这里碰壁了。
我考虑过一种只渲染当前页面的方法,但我不知道 FlowDocument 会有多少页面。
我使用的数据类型只是字符串,有时是复选框(只读)。
编辑:
处理时间看起来非常稳定,以 1 秒为余量。但是指数级的,3k 就已经是 164 秒了。
编辑2:
经过更多测试后,我发现问题是在我向 TableRow 添加 TableCell 时出现的。如果没有这个,只需要 1.6 秒。
What I try to do:
Generate a report based on data from the database, and then be able to view it and print it. (This in WPF C#)
How I do it: (dynamically, via code)
My Window is simple, it's just a FlowDocumentPageViewer with nothing in it.
- I load the data from the database
- Use LINQ to group it all properly
- Initialize a new Flowdocument
- Make a Table, with a RowGroup
- Loop my LINQed data and fill the RowGroup with TableRows that contain cells with the required data
- Add the Table to the Flowdocument
And this pretty much works fine, except when the amount of records goes to 10k. Then for some reason it just sucks up my CPU to 25% and takes 30 minutes. Scrolling is also pretty much impossible, not a thing happens, it just totally jams.
But when I got 1k records, it takes 18 seconds. And with 2k, its 74 seconds.
I do however, do not use the standard way of cells in Tables, I have to make a TextBlock for each cell, and use that with a BlockUIContainer. But after some testing it didn't seem to have much of an impact in generating the document.
Anyone with tips on stuff that I should worry about? Would be a major help, I'm hitting a brick wall here.
I thought about maybe a way that it only renders the current page, but I can't know how many pages there will be with a FlowDocument.
The type of data I use is just strings, and sometimes checkboxes (readonly).
Edit:
The time to process it seems very steady, with 1 second as margin. But exponential, with 3k it's already at 164 seconds.
Edit2:
After some more testing, I found out that the problem is when I add a TableCell to the TableRow. Without that, it only takes 1.6 seconds.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原因就在于分组。 wpf 下的此功能存在一个已知的性能问题。尝试删除分组进行测试,您会看到性能的提高!
The reason is the grouping. There is a known performance issue in this feature under wpf. Try remove grouping for test and you will see the increasing performance!