lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Why does Lua debug info, as well as error messages, contain line
numbers but not columns numbers?  It might be argued that column
numbers take up extra memory.  However, Lua's line number storage
(f->lineinfo) has a very low entropy.  Here's a dump of f->lineinfo
using tests/cf.lua:

  3 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 6 6 5 8 8 8 8 10 10 10 10 11
11 11 11 11 12 12 12 13 13 13 13 13 13 13 13 11 15 15 15 15 3 16

In the same space, we could instead store character positions.  With
less than 50% additional space, we could also store a line number <->
character position index:

  3 X 4 X 5 X 6 X 8 X 10 X 11 X 12 X 13 X 15 X 16 X
  (note: X represents character positions that I've left uncomputed)

Significant opportunities exist for compressing the above data so that
total memory requirements with column numbers would be less than the
current memory requirements on average.  A simple way may be to make
lineinfo be a byte array storing deltas of neighboring elements as
varints [1].  On average, this will require about 1 byte per
instruction, not including the above index.  Decoding speed is not
much of a concern since decoding debug information is limited to
exceptional circumstances.

[1] http://code.google.com/apis/protocolbuffers/docs/encoding.html#varints