Performance via Nesting - 2023.1 English

Vivado Design Suite User Guide: Using Tcl Scripting (UG894)

Document ID
UG894
Release Date
2023-06-14
Version
2023.1 English

When a Tcl command is executed from the Tcl console, the command is first being processed at the level of the Tcl interpreter. If there is no syntax error, the command is then executed at the C++ level. If the command returns a value, the C++ code sends the returned value to the Tcl interpreter through some layers of software. This layering back and forth between the Tcl interpreter and the low-level C++ code has some runtime penalty. However, when nesting is used within the same command, nested commands are directly called from the C++ code. The C++ code only returns to the Tcl interpreter once the whole command has been completed. For example, this code:

set nets [get_nets -hier]
set pins [get_pins -of_objects $nets]

is slower than this code:

set pins [get_pins -of_objects [get_nets -hier]]

This is because the first code sample creates an intermediate Tcl variable, nets.

However, it might sometimes be preferable to create intermediate Tcl variables if the results of these variables can be reused in other parts of the code.