#Performance question

9 messages · Page 1 of 1 (latest)

cinder tusk
#

So I've checked https://discord.com/channels/303440391124942858/1160209874878218370 , and improved my script.
But there's still a lingering question:
Is single listener always better than multiple listeners?

Here are three cases:

Case1: single listener with args and multiple ifs

const rc0 = {'diamond': '1', 'emerald': '2'}
const rc1 = ['gold_ingot', 'iron_ingot']
const rc_flat = Array.from(new Set([].concat(Object.keys(rc0), rc1, 'coal')));

ItemEvents.rightClicked(rc_flat, e => {
    if(rc0[e.item.id]) {
        //do something
    };
    if(rc1.contains(e.item.id)) {
        //do something
    };
});

Case2: single listener without args, but with multiple ifs

ItemEvents.rightClicked(e => {
    if(rc0[e.item.id]) {
        //do something
    };
    if(rc1.contains(e.item.id)) {
        //do something
    };
});

Case3: multiple listener with args and multiple ifs

ItemEvents.rightClicked(rc1, e => {
    //do something
});
ItemEvents.rightClicked(Object.keys(rc0), e => {
    //do something
});

Obviously case1 is faster than case2, but what about case1 and case2 compares to case3?

torn zenithBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

cinder tusk
#

it's 0:32 and i'm about to sleep, so replys will be delayed, sorry!

ocean juniper
#

i think most performant would be multiple listeners as then all code for this check will be run in java

#

case2 is probably the worst

cinder tusk
#

thanks!

ocean juniper
#

but i also think that case 1 and 3 aren't much different

glass domeBOT
#

Please close your ticket (with </ticket close:1054771505520717835> or the button atop this thread) once you resolved your issue! This also helps others that would like to help out, as they don't have to look into this thread to check if it has been resolved by now.

Do you have any other questions regarding your issue? Feel free to ask!
Note: You should generally create a new post for unrelated issues.

cinder tusk
#

dang