awesome-print / awesome_print

Pretty print your Ruby objects with style -- in full color and with proper indentation
http://github.com/michaeldv/awesome_print
MIT License
4.07k stars 454 forks source link

Optimizations #333

Closed paddor closed 1 month ago

paddor commented 6 years ago

To make AwesomePrint usable in a high-traffic, colorized log, I made a few optimizations.

Here the first few lines of RubyProf's profiling before (left) and after (right):

Measure Mode: wall_time                                             Measure Mode: wall_time
Thread ID: 16869000                                              |  Thread ID: 8005260
Fiber ID: 119289720                                              |  Fiber ID: 85516140
Total: 168.812981                                                |  Total: 166.237770
Sort by: self_time                                              Sort by: self_time

 %self      total      self      wait     child     calls  name                          %self      total      self      wait     child     calls  name
  9.86     34.460    16.649     0.000    17.811  8339561   AwesomePrint::Colorize#colorize           |   83.78    166.237   139.275     0.000    26.962        1   <Module::EventMachine>#run_machine
  6.25    168.812    10.549     0.000   158.263        1   <Module::EventMachine>#run_machine            |    1.42      4.825     2.368     0.000     2.458   875843   AwesomePrint::Colorize#colorize
  2.82      4.769     4.769     0.000     0.000 38670951   Symbol#===                        |    1.34      2.338     2.233     0.000     0.105     6249   <Module::Marshal>#load
  2.67      4.510     4.510     0.000     0.000  1397819   String#sub!                       |    0.89      1.473     1.473     0.000     0.000   803770   String#%
  2.40      5.402     4.052     0.000     1.349  3515541   AwesomePrint::Inspector#printable             |    0.44      0.729     0.728     0.000     0.000   141140   String#sub!
  2.13      3.603     3.603     0.000     0.000  7434729   Kernel#method                     |    0.38      1.046     0.628     0.000     0.418   245337   AwesomePrint::Formatters::BaseFormatter#align
  1.96      3.316     3.316     0.000     0.000  7434722   AwesomePrint::Inspector#colorize?             |    0.29      0.480     0.480     0.000     0.000   771620   AwesomePrint::Inspector#colorize?
  1.78     13.034     2.998     0.000    10.036  3515541   Enumerable#grep                   |    0.28      0.463     0.463     0.000     0.000   610388   Symbol#to_s

Here's a longer profile diff.

paddor commented 6 years ago

It seems that broken spec is broken even for the current master, at least on my system. Any ideas?

paddor commented 6 years ago

@imajes ping

imajes commented 5 years ago

@paddor hey- thanks for all this, and sorry for taking so long to get back to you. New year's resolution. :)

Can you rebase against master please so we can get travis passing, and then we can start to look at these pieces? I think overall there is good stuff here but i think a few tweaks might get it even better. thanks!!

really looking forward to landing this.