nixnest / scepter

Spiritual successor to Nixbot
https://discord.gg/g3gD5xd
MIT License
6 stars 5 forks source link

Avoid fetching guild's prefix from disk in every message #44

Closed ldelelis closed 4 years ago

ldelelis commented 5 years ago

https://github.com/nixnest/scepter/blob/f61a8242d56e8ab7b37428e60f81f2c991861e08/scepter.ts#L229

Baseless and unmeasured supposition, but hitting the db with every message the bot sees could be heavily bogging down its performance.

Handle this by caching in-memory a map with guild-id => prefix, and a function that accomplishes the following.

known-as-dan commented 4 years ago

From the enmap docs:

Very Fast: Since Enmap resides in memory, accessing its data is blazing fast (as fast as Map() is). Even with persistence, Enmap still only accesses data from memory so you get it almost instantly.

ldelelis commented 4 years ago

@Known-As-Dan cc @tadeokondrak

Fair enough. Even so, is it a good idea to do a lookup every single message, considering the prefix isn't something that changes on runtime?

known-as-dan commented 4 years ago

@Idelelis Just not sure it's worthwhile, considering the likely small performance improvement. I'd say implement it if you think it'd make a "big-picture" kind of difference.

ldelelis commented 4 years ago

Nah, no noticeable performance changes will be gained from this. And even as an aesthetic change it's not justified, given that we may implement runtime configuration of prefix in the future. Closing this.