News for hackers. Stuff that matters.
Re:Ruby 2.1: Profiling Ruby by VeejayRampay on Wednesday December 25, 2013 @01:59PM (#6963845)
I wonder if this API allow will foster a big movement to track down all the performance-hungry calls in say, Rails, and help the framework move forward in terms of efficiency. This is really a welcome addition anyway.
Re:Ruby 2.1: Profiling Ruby by akx on Wednesday December 25, 2013 @06:49AM (#6962841)
I think TRWTF here is that checking for (query string?) parameter existence runs a regexp...
Re:Ruby 2.1: Profiling Ruby by sams99 on Wednesday December 25, 2013 @08:17AM (#6962942)
Some of us like to pre-divine a world devoid of bugs and silliness, others like to provide us with tooling to track stuff down
Re:Ruby 2.1: Profiling Ruby by wrl on Tuesday December 24, 2013 @09:42PM (#6961980)
So, I'm a Ruby neophyte. Why did adding parenthesis speed that line up so much?
Re:Ruby 2.1: Profiling Ruby by MaulingMonkey on Tuesday December 24, 2013 @09:55PM (#6962007)
Rewritten in longer form, assuming I've made no mistakes, the two versions are equivalent to...

  if params[:user_id].present?
    if !@owner
      @owner = User.find_by_login(params[:user_id])
    end
  end
vs

  if !@owner
    if params[:user_id].present?
      @owner = User.find_by_login(params[:user_id])
    end
  end
Checking the member variable truthiness is presumably faster than a dictionary lookup followed by a call to "present?". As @owner is probably frequently/always true after the first call (it will be unless find_by_login returns false/nil/? or another method resets @owner, given the same instance), this leads to fewer dictionary lookups and present? calls, resulting in a performance increase.

EDIT: Well that was an amusing spam of simultaneous answers.

Re:Ruby 2.1: Profiling Ruby by Mithaldu on Tuesday December 24, 2013 @09:50PM (#6961998)
I don't write Ruby, but it's close enough to Perl that i can tell you. Precedence is the reason.

The first line with more explicit precedence is this:

    if( params[:user_id].present?) {
        @owner ||= User.find_by_login(params[:user_id]) 
    }
The second line is this:

    @owner ||= (
        User.find_by_login(params[:user_id]) if params[:user_id].present?
    )
In other words, the first version always ran the present? method, while the second version only did so if @owner was false.
Re:Ruby 2.1: Profiling Ruby by Moto7451 on Tuesday December 24, 2013 @09:50PM (#6961997)
I haven't done too much Ruby myself, but the line looks sufficiently Perl like I believe the subtle change converted the first line (rolled out) from:

(excusing my Perl-Ruby mashup)

  if (params[:user_id].present){
    if (!@owner){
      @owner = User.find_by_login(params[:user_id]);
    }
  }
to:

  if (!@owner){
    if (params[:user_id].present){
      @owner = User.find_by_login(params[:user_id]);
    }
  }
Now the call params[:user_id].present is only made if @owner lacks a value.
Re:Ruby 2.1: Profiling Ruby by stock_toaster on Tuesday December 24, 2013 @09:57PM (#6962011)
Assignment has higher precedence than if, so the line originally would have evaluated as:

  (@owner ||= User.find_by_login(params[:user_id])) if params[:user_id].present?
Thus always testing the if, and then conditionally setting @owner. The new line checks the existence of @owner before evaluating the if by using parens to set precedence.
Re:Ruby 2.1: Profiling Ruby by jbverschoor on Tuesday December 24, 2013 @09:48PM (#6961992)
@owner ||= User.find_by_login(params[:user_id]) if params[:user_id].present? means:

  if params[:user_id].present?
    if not @owner
      @owner = User.find_by_login(params[:user_id])
    end
  end
@owner ||= (User.find_by_login(params[:user_id]) if params[:user_id].present?) means:

  if not @owner
    if params[:user_id].present?
      @owner = User.find_by_login(params[:user_id])
    end
  end

So everytime someone called owner() to get the owner of a repo, the regex was checked
Re:Ruby 2.1: Profiling Ruby by gazarsgo on Wednesday December 25, 2013 @02:20AM (#6962479)
Why is line level profiling so non-existent for dynamic languages? Function level just doesn't cut it, esp. w/ the zillions of monkey patches in Ruby.
Re:Ruby 2.1: Profiling Ruby by sams99 on Wednesday December 25, 2013 @08:13AM (#6962934)
Wait, what about stackprof rb-lineprof flamegraph rack-mini-profiler
Re:Ruby 2.1: Profiling Ruby by Mithaldu on Wednesday December 25, 2013 @08:13AM (#6962935)
My theory is that it takes both a certain amount of pressure to create those tools, a certain amount of expertise and a certain amount of tooling available from the language. Due to being old, Perl has all of these and in Devel::NYTProf has a more than excellent profiler that goes beyond line, into statement level. See for example these profiling runs created with it: https://dl.dropboxusercontent.com/u/10190786/ppi_bench.zip
Re:Ruby 2.1: Profiling Ruby by copx on Wednesday December 25, 2013 @04:27AM (#6962667)
>Why is line level profiling so non-existent for dynamic languages?

It isn't. As usual the answer is LuaJIT (sorry, I am a fanboy, got to admit it): http://permalink.gmane.org/gmane.comp.lang.lua.luajit/3413

Re:Ruby 2.1: Profiling Ruby by girvo on Wednesday December 25, 2013 @07:50AM (#6962911)
I was just looking at phpdbg and xdebug yesterday, and they do it, iirc :) so, not impossible, but Ruby does do more stuff dynamically.
Re:Ruby 2.1: Profiling Ruby by kbar13 on Tuesday December 24, 2013 @10:14PM (#6962042)
At first I didn't realize OP was a GitHub employee and thought he was munging his company's GHE appliance :o

Cool read!