[Python-Dev] Simplify lnotab? (AST branch update)

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Oct 14 09:07:05 CEST 2005

Phillip J. Eby wrote:

> A more 
> compact scheme is possible, by using two tables - a bytecode->line 
> number table, and a line number-> file table.  
> If you have to encode multiple files, you just offset their line numbers 
> by the size of the other files,

More straightforwardly, the second table could just be a
bytecode -> file number mapping. The filename is likely to
change much less often than the line number, so this file
would contain far fewer entries than the line number table.
In the case of only one file, it would contain just a single
entry, so it probably wouldn't even be worth the bother of
special-casing that.

You could save a bit more by having two kinds of line number
table, "small" (16-bit entries) and "large" (32-bit entries)
depending on the size of the code object and range of line
numbers. The small one would be sufficient for almost all
code objects, so the most common case would use only about
4 bytes per line of code. That's only twice as much as the
current scheme uses.


More information about the Python-Dev mailing list