Optimisation of logging on a hot code path

  • From: Thijs Schreijer <thijs@xxxxxxxxxxxxxxxxx>
  • To: "luajit@xxxxxxxxxxxxx" <luajit@xxxxxxxxxxxxx>
  • Date: Fri, 19 May 2017 07:53:50 +0000

I have an occasional need for extensive logging on a very hot codepath. I’m 
wondering what the best approach would be to this?

I’ve seen some empty log functions, like:

local log
if loglevel > 2 then
  log = ngx.log
else
  log = function() end
end

But I’d expect it to still be a function call at runtime that I’d rather avoid. 
(Though it would be nice if LuaJIT would optimise it away)

Any best practices to share?

Thijs

Other related posts: