Nifty obj creation unbelievable slow

I am filling an score table that may have thousands of records of different types, I am using the follow code to fill each line of the table ( an scrollpanel ) :

    Element newPanel = new PanelBuilder() {{
            height(linesize+"px");
            width("100%");
            childLayoutHorizontal();
        }}.build(nifty, screen, bigPanel) ;

    new TextBuilder() {{
        width("20%");
        height("100%");
        color(linecolor);
        text( position );
        textHAlignLeft();
        valignCenter();
        style("game-font-list");
    }}.build(nifty, screen, newPanel) ;

    new TextBuilder() {{
        width("42%");
        height("100%");
        color(linecolor);
        text( playername );
        textHAlignLeft();
        valignCenter();
        style("game-font-list");
    }}.build(nifty, screen, newPanel) ;

    new TextBuilder() {{
        width("33%");
        height("100%");
        color(linecolor);
        text( playerrecord  );
        textHAlignRight();
        valignCenter();
        style("game-font-list");
    }}.build(nifty, screen, newPanel) ;

Each call of this is taking 1 sec or more to run !
There is anything I am doing wrong or could do to get it faster ?

I make similar calls all the time and they go much faster. I think your problem probably has to do with the fact that you are populating thousands of records into the nifty table. Populating a single scroll panel with thousands of objects is really an edge case so I doubt it was ever designed to handle that. Off the top of my head, you really have two options.

1 - Write a new nifty component that only adds the visible components and changes the data in the visible components as you scroll through them.

2 - Paginate your display to only show X number of records at a time and have a “backwards” and “Forwards” table.

1 Like

Hi @glh3586, thanks for your reply.
Yes, my problem is that I am populating a lot of lines, it starts to be slow after 10000 lines I think.
I dont think the problem is in the scrollpanel thought.
I am using an big panel inside the scrollpanel you see, I just make the maths and put this big panel inside the scrollpanel, then start to add panes inside ( the line panes ).
I think your solution may fix this problem, but I still dont get why its so slow…
I mean, if you just create an empty panel and using code start to put other empty panels inside it, it will get slow, I think there is an problem in the nifty implementation.

It’s not much of a Nifty implementation, your case is a special one and many UI’s for games become slow when you add so many lines (10000… wow o_O) since they are not usually meant for a case like that. The problem is not the scrollpanel, but the quantity of elements to be rendererd which is not that common in game UI. And in the rendering phase it may slow your project’s performance overall since it would want to render so much stuff.

@glh3586 proposed two great solutions that you should check out

Yes, as @bloodwalker said, it isn’t that the scrollpanel can be large but that it wasn’t built to hold a large number of objects. The number of objects is the problem you are running into.

I understand. Thanks for the help, I will follow this approach.