I am working on a page with several dynamically generated tables where the original developers used approximately the following logic:
<table>
<tr>...</tr>
<asp:PlaceHolder ID="ph1" runat="server" />
</table>
In the code behind:
// Do lots of stuff
HtmlTableCell cell = new HtmlTableCell();
// set cell text, formatting, etc
ph1.Controls.Add(cell);
// repeat the above logic for every cell in the table
In one page, methods like this are used to add up to 10-15 total rows, with 10-15 columns each spread over 4-5 tables. The table structures are set, so this could also be constructed by hard-coding the table structure in html and putting literals and labels in each cell. The page itself has some performance issues. This is one of the factors that could be contributing to the bad performance.
The question is:
It's not ideal, but I suspect that the real issue is the datasource that feeds that logic. Speed up whatever query it uses to get the data.
If they are they must be so marginal that you wouldnt notice. Ive coded a gridviewish control in this way with 10x50 cells and had no noticeable performance issues compared to static tables in similar size.
What you should strive for in most cases is :) :)
Short answer: highly unlikely.
Long answer: It really depends on your definition of "significantly". Assuming you are generating a typical HTML page on a decent server machine with a fast connection, the breakdown would go something like this:
The numbers are obviously estimates -- the important point is the cost of step (2) in relationship to all the others. Spending time optimizing step (2) when it constitutes a small share of the total cost is not a good use of developer time. As CodeSpeaker said, clean and maintainable code is a far better investment. If the total time to load the page is really an issue, attack the dominant costs first (steps 1 and 4) before moving on to the rest of the pipeline.
通过使用文字(在任何一个方向上)和你提到的卷,我怀疑你甚至可以衡量差异,这个代码在性能上不会显着增强。
Yaakov, I'd worry more about what happens on the client side with such rendered code. I mean... it depends on HOW do you setup cell rendering (formatting, CSS, classes/ids) for each individual cell.
If you end up with large class names / ids and inline CSS!!! , then you should look into manually generating the table structure (without even using literals). It looks to me that all of those tables contents are just text so you could render it naturally without any kind of control overhead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.