177177177
1771771772y ago

About performance

if a function takes only one paramater and i pass unnecessary additional parameters would it affect the performance of just the function part of the code?
function echo(sentence) {
console.log(sentence)
}

echo('hello')

echo('hello', 'bye', 'okay')
function echo(sentence) {
console.log(sentence)
}

echo('hello')

echo('hello', 'bye', 'okay')
this is what im caonfused abt i have a object, every value is a function that takes the same parameter payload except only one value that takes an additional second parameter args i want to know which way from these two would perform better
const handler = {
READY: (payload, args) => {},
GUILD_CREATE: (payload) => {},
MESSAGE_CREATE: (payload) => {}.
// ...about 30 more
}


// should i do this
handler[eventName](payload, args)

// or this
if (eventName === 'READY') handler[eventName](payload, args)
else handler[eventName](payload)
const handler = {
READY: (payload, args) => {},
GUILD_CREATE: (payload) => {},
MESSAGE_CREATE: (payload) => {}.
// ...about 30 more
}


// should i do this
handler[eventName](payload, args)

// or this
if (eventName === 'READY') handler[eventName](payload, args)
else handler[eventName](payload)
4 Replies
177177177
1771771772y ago
sorry for not using typescript types, i asked the same question in a javascript server, i copy pasted here too
AapoAlas
AapoAlas2y ago
IIRC It does have some effect, yes, but nothing particularly horrible. I expect the latter might be better simply because less parameters means less polymorphism.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
177177177
1771771772y ago
i see tyvm!