I don't think any one can help with this.

Performance issues are usually very surprising. Its almost never as simple as 
use seq instead of table. You need to profile your code. Find the hot paths and 
try to optimize them a way.

Here are some tips on writing fast code:

  * Have an open mind - performance issues usually happens in the least places 
you expect. Don’t jump at the code with “oh that looks slow”. It probably isn't 
the problem.
  * Profile your code. Measure! Measure! Measure! Put little this function took 
N seconds if you don’t want to invest in learning a profiler.
  * Maybe even write little benchmark scripts that just test important parts of 
your program - sort of like unit tests.
  * Maybe an earlier version of your program ran fast, and something has made 
it slow recently, you can try looking at the changes.



Some functions will be way more time than other functions. That is your hot 
path. You should only focus on things that are slow. Only after you have 
identified your hot path you can fix it.

Only after you measure you can get into figuring out the problem:

  * Are your for loops slow? Sometimes a better algorithm can just be faster. 
If you are looping over objects many times … maybe a better access pattern 
would help such as a hash table? Be wary of repeating work over and over again. 
Be wary of linear scans and nested for loops.
  * Can a simple cache help? Everything in computer runs on caches there are 
caches everywhere: RAM, Hard Drive, HTTP, DBs… why shouldn't your code be any 
different?
  * Is an external part that is slow? Querying a DB, reading files, or making 
http requests?
  * Are object allocations and deallocations slow? Instead of creating a ton of 
ptr objects try creating an array of “non ptr” regular objects so that memory 
can be contagious.
  * Are you converting a ton of string numbers to real numbers and back to 
strings?



Always measure before and after the change. Even after you made a change, and 
think its faster, it might not be. Measure! Measure! Measure!

After fixing your hot path and it becomes fast, now another piece of code would 
be the slowest one. Try fixing it next. 

Reply via email to