memory cost and execution time exploding of nested namespaces
for {set i 0} {$i < 10000} {incr i} {
set name [namespace eval ${name}[set name {}]::namespace$i {
namespace current
}]
}
It seems that the fully-qualified name of each created namespace is getting stored somewhere.
Seems to affect 8.5 and 8.6 in same manner also.
Additionally it've very large execution time exploding. Just as comparison to not-nested (>= 8.6, x86):
# not nested:
set i 0; time {namespace eval ::namespace[incr i] {}} 10000
----> 4.74 microseconds per iteration (and 8.0MB memory)
# nested:
set name {};
set i 0; time {namespace eval [set name ${name}::namespace[incr i]] {}} 10000
----> 70110.60 microseconds per iteration (and 770.0MB memory)
This difference looks in 8.5 still many times worse and the execution time exploding is very grave (with the similar memory consumption like 8.6).
% # not nested:
% set i 0; time {namespace eval ::namespace[incr i] {}} 10000
2.91753049225468 microseconds per iteration
%
% # nested:
% set name {};
% # 1. thousand:
% set i 0; time {namespace eval [set name ${name}::namespace[incr i]] {}} 1000
1153.3163043544507 microseconds per iteration
% # 2. thousand:
% set i 0; time {namespace eval [set name ${name}::namespace[incr i]] {}} 1000
7032.770893726276 microseconds per iteration
% # 3. thousand:
% set i 0; time {namespace eval [set name ${name}::namespace[incr i]] {}} 1000
18984.08208553774 microseconds per iteration
%
The memory consumption going to large full-qualified namespace name.
Following example explain it (has comparable memory consumption as "namespace eval"):
set name {};
set i 0; time {set ns($i) [set name ${name}::namespace[incr i]]} 10000
> pooryorick:
It seems that the fully-qualified name of each created namespace is getting stored somewhere.
Yes, see struct Namespace declaration "fullName" in tclInt.h. It is currently impossible without this member, because used everywhere and the auto-retrieving on demand would be admittedly possible, but will used almost immediately.
I'll take a look later what would be possible to optimize it.