samg / timetrap

Simple command line timetracker
http://rubygems.org/gems/timetrap
Other
1.48k stars 116 forks source link

Slow to run #75

Closed mkropat closed 10 years ago

mkropat commented 10 years ago

Love the tool, but it is inexplicably slow for such a simple cli tool. Is this normal or is this something funky with my ruby? (I'm not a ruby guy.)

These are runtimes after everything is “warm” (delays are closer to 1s when cold):

$ time t d >/dev/null

real    0m0.471s
user    0m0.404s
sys 0m0.048s

$ ruby-prof -s total `which t` d
[snip]
Total: 0.389718
Sort by: total_time

 %self      total      self      wait     child     calls  name
  0.02      0.390     0.000     0.000     0.390        2   Global#[No method] 
  0.04      0.386     0.000     0.000     0.386        1   Kernel#load 
  0.02      0.377     0.000     0.000     0.377      139  *Kernel#require 
  0.25      0.373     0.001     0.000     0.372      139  *Kernel#gem_original_require 
  5.67      0.230     0.022     0.000     0.208     1110  *Array#each 
  0.10      0.138     0.000     0.000     0.138     1110  *Class#new 
  1.43      0.130     0.006     0.000     0.124        1   Getopt::Declare#initialize 
  0.01      0.109     0.000     0.000     0.109        7  *<Module::Sequel>#require 

$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]

$ rvm version

rvm 1.23.3 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
samg commented 10 years ago

Unfortunately I think the bulk of the time is just spent loading the gem's dependencies. Startup time isn't ruby's strongest attribute, and rubygems has had various problems over the years which have contributed to slow loading of an app's environment (I believe some of these are fixed, but some remain).

I've done some tests locally and have similar numbers to what you report.

Sadly even doing something like this is fairly slow, and cuts timetrap's code entirely out of the equation:

$ time ruby -e 'require "sequel"'

real    0m0.380s
user    0m0.323s
sys 0m0.052s

In fact just loading the ruby 2.0 interpreter takes almost 100 ms on my laptop.

$ time ruby -e ''

real    0m0.086s
user    0m0.050s
sys 0m0.033s

I don't think there's any simple way to speed it up. One approach would be to preload the environment (either as a server that commands could be streamed to, or as a parent process that could be forked). Both these approaches seem like overkill for a tool like this.

Probably a better approach would be to just use the half second pause as an opportunity to reflect on the work you've just completed or are about to embark on.

mkropat commented 10 years ago

I dig your philosophy. You're right, timetrap is still very usable. I will, however, think twice before ever creating a cli tool in Ruby.

jostber commented 7 years ago

My timetrap DB is getting quite large with many thousand entries and it has gotten much slower lately. Is there a way to move the archived entries in another DB or another way make it faster again?