JimTheCactus / Gummybot

An IRC Chat Support Bot for the Artist's Training Ground Alumni
GNU General Public License v2.0
0 stars 0 forks source link

Funsubs precalculation should be done once and optimize regex searches #49

Open JimTheCactus opened 9 years ago

JimTheCactus commented 9 years ago

Gummy currently does the matrix inversion on the funsubs data on load and once an hour. On top of that, gummy currently uses a for loop to test each of the possible substitutions. This is inefficient as it means running through the string multiple times.

The best approach would be to precalculate the funsubs only once and precompile a single regex that finds the various funsubs. This would speed up the calculation and reduce wasted overhead.

JimTheCactus commented 9 years ago

Hint: http://stackoverflow.com/questions/952998/is-there-a-way-to-precompile-a-regex-in-perl

JimTheCactus commented 9 years ago

One thing worth looking at is to create a cache folder with the computed classes. When a file is needed in a given line, it checks a memory cache to see if that file has already been loaded. If not, the lines are loaded (maybe it's time to grab File::Slurp?) and the cache is held in memory until the line is finished so %pony, %pony, %pony doesn't load the pony file 3 times.