TIP 530: Control over performance impact of TIP 280

Login
Author:         Leon Manukyan <[email protected]>
State:          Draft
Type:           Project
Vote:           Pending
Created:        13-Dec-2018
Tcl-Version:	8.6
Post-History:
Tcl-Branch:     tip-530

Abstract

A compile-time macro and an environment variable are introduced which enable a user of Tcl to trade some functionality brought by [280] for better performance.

Background and Motivation

[280] extended Tcl's abilities for introspection with the info frame command able to determine the location of its call, i.e., the name of the file the code is in, and the absolute line number in that file.

Though that functionality was very useful while debugging Tcl scripts it hardly had any other use, while at the same time negatively impacting the performance of Tcl code. [378] has already addressed the most critical degradation of performance caused by [280], however a milder slowdown has remained. The mere fact that line continuations are tracked unconditionally and such information, if present, is associated with a respective Tcl object through an external hash map results in a relatively expensive check performed in TclFreeObj() for every single object. The issue has first been discussed at comp.lang.tcl.

This TIP now proposes to put the execution of the respective part of [280]'s implementation under user control, allowing them to trade info frame-exactness for speed, and vice versa.

Run-time control

The environment variable TCL_INFO_FRAME_ENABLE_ACCURATE_LINE_NUMBERS is checked during the startup of the main Tcl interpreter and handling of line continuations is fixed (until the end of execution of the process) as follows:

Build-time control

The default value assumed for the environment variable TCL_INFO_FRAME_ENABLE_ACCURATE_LINE_NUMBERS when it is unset is defined by the compilation macro of the same name. That is a Tcl interpreter built with -DTCL_INFO_FRAME_ENABLE_ACCURATE_LINE_NUMBERS=X will behave by default as if the env var TCL_INFO_FRAME_ENABLE_ACCURATE_LINE_NUMBERS is set to X (but the actual value of that variable, if it is set, will be respected).

The value can be set at configure time (on Unix) via the --enable-line-continuations option, which defaults to on.

Default Setting

Unless users don't take any deliberate action (assuming that they didn't use the said compilation macro in their build processes or the environment variable in their flows) they won't notice any change in behavior.

Reference Implementation

A reference implementation is provided at https://core.tcl-lang.org/tcl/artifact/3b68b7cd8131a42a .

Copyright

This document has been placed in the public domain.