Skip to content

Unnessecary Sidebar updates?? #5

Description

@IIHERO4

Hello, i noticed in our server there was alot of cpu-time going to sending scoreboard (in Bedwars1058) so which at time i thought it was normal.

I looked into the source and i saw that the plugin sends alot of unnessecary packets, i fixed it by checking prefix and suffix before and after setting content which is already a huge improvement as for my case the only thing changing from packet to packet is Sidebar.suffix and Sidebar.prefix.

Although this change worked nicely for my case, It needs a look from you as developers that uses your library may implement their own ScoreLine which will cause unexpected behavior if we are just checking for prefix and suffix.

My Patch:

    public void refreshPlaceholders() {
        for (ScoreLine str : this.lines) {
            if (str.text.isHasPlaceholders()) {
                // Some code here in parsing content
                
                String oldSuffix = str.suffix;
                String oldPrefix = str.prefix;
                str.setContent(content);

                // ignore Intellij Idea warning if present
                if (!oldSuffix.equals(str.suffix) || !oldPrefix.equals(str.prefix)) { 
                    str.sendUpdate();
                }
            }
        }
    }

This is old version of bw1058, But its equivilant to https://github.com/andrei1058/SiderbarLib/blob/6731c0aca53cf0390b14a08f9e55966bdf1faee1/sidebar-base/src/main/java/com/andrei1058/spigot/sidebar/WrappedSidebar.java#L138-L145

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions