[CLOSED] Caching Dynamic Grids

Page 2 of 4 FirstFirst 1234 LastLast
  1. #11
    I was able to reproduce using the sample below. We are investigating.

    <%@ Page Language="C#" %>
    
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET Examples</title>
        
        <script runat="server">
            public void Page_Load(object sender, EventArgs e)
            {
                GridPanel.Config config = GetGrid();
     
                //GridPanel gridPanel = new GridPanel.Config();
                
                Viewport1.Items.Add(new GridPanel(config));
            }
            
            public static GridPanel.Config GetGrid()
            {
                List<object> data = new List<object>();
            
                for (int i = 1; i <= 10; i++)
                {
                    data.Add(new { ID = "P" + i, Name = "Product " + i });
                }
    
                GridPanel.Config config = new GridPanel.Config
                {
                    Height = 200,
                    EnableColumnHide = false,
                    Store = 
                    { 
                        new Store 
                        { 
                            Model = {
                                new Model {
                                    IDProperty = "ID",
                                    Fields = 
                                    {
                                        new ModelField("ID"),
                                        new ModelField("Name")
                                    }
                                }
                            },
                            DataSource = data
                        }
                    },
                    ColumnModel =
                    {
                        Columns = 
                        { 
                            new Column { Text = "Products's Name", DataIndex = "Name" }
                        }
                    }
                };
    
                return config;
            }
        </script>
    </head>
    <body>    
        <form runat="server">
            <ext:ResourceManager runat="server"></ext:ResourceManager>
            <ext:Viewport runat="server" ID="Viewport1" Layout="Fit">
                <Items>
                    
                </Items>
            </ext:Viewport>
        </form>
    </body>
    </html>
  2. #12
    The problem that columns are not applied from config because ColumnModel has no setter. We will investigate it
    Few words about the topic

    I don't think that you need to cache Ext.Net config because Model, Column are controls also but control cannot be cached (control is related with one page instance only)

    You have to cache data from DB (I don't know how it is represented after reading from DB), after that you can build the grid when it is required refing the data from cache.

    Summary: read data from DB, cache it (not Ext.Net config, not control, just data which describes a widget), build a widget according cached data
  3. #13
    The data is already being cached. But the data determines the logic on how, lets say, a column should be rendered. So even if it is cached, i need to run a logic to determine the right column to render. This is my sample code :

    
    private void RenderGridMe()
    {
        List<Entity> columns = Application["TESTCOLUMNS"];
    
        GridPanel gridPanel = new GridPanel();
    
        foreach (Entity column in columns)
        {
            switch (column.DataType)
            { 
                case "date":
                case "datetime":
                    gridPanel.ColumnModel.Columns.Add(CreateDateColumn(column));
                    break;
    
                default:
                    gridPanel.ColumnModel.Columns.Add(CreateTextColumn(column));
                    break;
            }
        }
    
        ViewPort.Items.Add(gridPanel);
    }
    
    public DateColumn CreateDateColumn(Entity entity)
    {
        DateColumn column = new DateColumn();
        string label = entity.Label;
        string format = entity.Format;
    
        column.Text = Strings.SplitCamelCase(label);
        column.Sortable = true;
        column.Flex = 1;
        column.MaintainFlex = true;
        column.DataIndex = entity.DataColumn;
        column.Groupable = false;
    
        if (entity.Editable)
        {
            Ext.Net.DateField dateField = new Ext.Net.DateField();
            dateField.Format = format;
            column.Editor.Add(dateField);
        }
    
        if (!string.IsNullOrWhiteSpace(format))
            column.Renderer.Fn = ("Ext.util.Format.dateRenderer('" + format + "')");
    
    
        return column;
    }
    I want to skip the column creation part and just shorten the code to this:

    private void RenderGridMe()
    {
        GridPanel gridPanel = Application["CACHEDGRID"];
        
        //IF NOT IN CACHE, I CAN RUN THE LENGTHY METHOD AND CACHE IT, WHICH SHOULD BE ONCE EVERY AFTER - APPLICATION RESTART.
    
        ViewPort.Items.Add(gridPanel);
    }
    Is this something not entirely possible?

    Thanks for your time..

    -Allan
  4. #14
    Did you measure the performance of creating a control and without it? I agree with @jchau and Vladimir that even if it is possible it doesn't worth because creating controls on the server-side is not slow operation. Moreover, caching config of the control can lead to more unexpected results and doesn't look like a solution to increase performance and look like "Tilting at windmills".

    If your controls depends on some database values it can make sense but I would suggest to save this values into objects and use them in creating of controls.

    It doesn't mean that we don't like it or don't want to help you but it is more important to understand the reason to do that.
  5. #15
    Hi Baidaly,

    Thank you for spending time to look into this. As I mentioned before, the data is already being cached. Even if it's not, there is no problem with the database query, the issue that is taking so long is the actual creation of columns since a lot of checks needs to be done to render the accurate type of column (as i have described in the code earlier). I have some 4-6 grids per page, with an average of 40 columns per grid.

    The GridPanel.Config object should work fine, however, i believe there is a problem serializing it back and forth when calling the grid.ToConfig() then using the string to transform it back to GridPanel.Config(string). That alone does not work pretty well. But if it works, i believe I can use that ToConfig() call to cache the grid.

    I realized that calling this ToConfig() method - for javascript to use (via ajax) - works pretty well, i was hoping this would work too when called on the server side directly.

    Thanks,
    Allan
  6. #16
    Have you actually tested the slowness of creating columns? Or are you just guessing because it looks like alot of code? I can assure you that creating 1,000 columns will take less than a millisecond. Unless your checks are doing database hits or some complex logic (like looping 1 million times or crazy recursion or lots of string manipulation), I dont see how creating 4-5 grids on the server side can be slow. In order of slowness, performance issues are usually related to: Database >> Browser dom engine >> Browser javascript engine >> server side code.
  7. #17
    Quote Originally Posted by jchau View Post
    Have you actually tested the slowness of creating columns? Or are you just guessing because it looks like alot of code? I can assure you that creating 1,000 columns will take less than a millisecond. Unless your checks are doing database hits or some complex logic (like looping 1 million times or crazy recursion or lots of string manipulation), I dont see how creating 4-5 grids on the server side can be slow. In order of slowness, performance issues are usually related to: Database >> Browser dom engine >> Browser javascript engine >> server side code.
    Hi jchau,

    Thank for spending your time trying to understand the issue. But your assurances are not comforting at all. 1000 columns takes about 17 milliseconds, your guesstimate of less than 1 millisecond does'nt fly. Here is the code that was ran under an i7 16Gb RAM:

    Stopwatch watch = new Stopwatch();
    watch.Start();
    
    GridPanel gridPanel = new GridPanel();
    for (int i = 0; i < 1000; i++)
    {
         Column column = new Column();
         gridPanel.ColumnModel.Columns.Add(column);
    }
    
    watch.Stop();
    
    Int64 elapsed = watch.ElapsedMilliseconds;
    Assert.IsTrue(elapsed > 0);
    I appreciate you taking notice of my post but I have resolved the issue myself. I have extended the GridPanel class to ICloneable, and I tried caching it. Since the initial problem rendering it is the Tokenizer issue from Transformer.Net, cloning it and re-rendering generates and new token and the issue went away. I hope this helps someone else by reading this post.

    Since the start of this thread, you have NOT offered a solution to the problem. What you did is just question the validity of the issue and propose something that is already being done. As far as I know, the people who do this either has

    1. No idea on how to resolve the issue, or
    2. Does not understand the question at all.

    I came here to find answers. You came here to troll.

    Thanks,
    Allan
  8. #18
    Sorry if you think i am trolling, but i am just stating that caching UI control instances is not a good practice nor does it save that much time. Is 17ms really that important? Isn't this a bit of premature optimization? I am not offering a solution to your problem, because I think your problem lies elsewhere. Instead of banging your head against a dead end, you should step back and see why what you are doing is wrong.

    Here is a link straight from Microsoft saying not to do this:
    http://blogs.msdn.com/b/tess/archive...ion-scope.aspx

    A simple search on google will yield similar forum posts and stackoverflow topics advising people not to do this. However, it's your project. Do what you want.
  9. #19
    Quote Originally Posted by jchau View Post
    Sorry if you think i am trolling, but i am just stating that caching UI control instances is not a good practice nor does it save that much time. Is 17ms really that important? Isn't this a bit of premature optimization? I am not offering a solution to your problem, because I think your problem lies elsewhere. Instead of banging your head against a dead end, you should step back and see why what you are doing is wrong.

    Here is a link straight from Microsoft saying not to do this:
    http://blogs.msdn.com/b/tess/archive...ion-scope.aspx

    A simple search on google will yield similar forum posts and stackoverflow topics advising people not to do this. However, it's your project. Do what you want.
    Hi jchau,

    That is exactly my point. It was a dead end for you because:

    1. You have no idea how to resolve the issue, and
    2. You do not understand the question at all.

    I was asking to cache the config. So i can re-use it. Apparently, even the support team admits there is an issue serializing the config back. Didn't I just discover something that the support team can improve on?

    I may sound like i am being mean, but i am just stating my point. And next time, please do not throw in numbers you can not support. I agree that the reply about the millisecond is unimportant. But that came and started from the context of your reply. And if the context of your reply is unimportant or irrelevant, it simply means you are trolling.

    Please troll on other issues as this issue of mine has been resolved.

    Thanks,
    Allan
  10. #20
    Hi,

    You should understand that ASP.NET controls cannot be cached. It is not Transformer.Net issue. Control life cycle should not be cyclic, control is related with one page instance only (but page instance is new for each request). So, server side instance of control should be destroyed after server side rendering. Config of Gid cannot be cache if it contains other controls (Store, Model, Column and etc). We will fix config apply issue but it doesn't solve your problem because controls must be recreated, not cached

    Since when 17ms is bad in web programming? I am absolutely agree is that what you try to do is "premature optimization"
    Rendering 1000 columns on client side will hang a browser on many seconds therefore 17 ms will be nothing for end user

    I don't understand why do you want to cache UI? What advantages can give it? Controls server side creating/rendering is not bottle neck.

    I am not sure why did you offence to @jchau because his advice are correct and I agree with him, need to cache bussiness data, not UI

    So, my summary will be next: cache data from DB, don't cache controls because UI caching will improve nothing
Page 2 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. [CLOSED] Ext.select caching problem
    By fpw2377 in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Jul 12, 2012, 10:43 AM
  2. [CLOSED] Drag & Drop Between Dynamic grids
    By imaa in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Dec 05, 2011, 12:34 PM
  3. [CLOSED] Caching the ResourceManager/ExtJs library
    By SouthDeveloper in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Feb 13, 2011, 12:51 PM
  4. [CLOSED] Desktop application caching of web pages
    By ogokgol in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 08, 2011, 8:39 AM
  5. [CLOSED] How to turn on resource caching?
    By jchau in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 28, 2009, 7:01 PM

Tags for this Thread

Posting Permissions