Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2007-01-04
01:01 • Ticket [1465666fff] 8.5 lists sometimes uses more memory for 8.4.. status st... artifact: aaf50a26b2 user: dkf
2007-01-03
22:49 • Closed ticket [1465666fff]. artifact: da47e8ed74 user: kennykb
2006-06-22
02:09 • Ticket [1465666fff]: 4 changes artifact: 77f3e7f8c2 user: dgp
02:02 • Ticket [1465666fff]: 4 changes artifact: d5655cb9ee user: dgp
2006-06-21
21:50 • Open ticket [1465666fff]. artifact: 06c922aa89 user: afredd
20:39 • Pending ticket [1465666fff]. artifact: 5b371d4d56 user: kennykb
20:37 • Ticket [1465666fff]: 4 changes artifact: fbc31e68dd user: kennykb
03:40 • Ticket [1465666fff]: 5 changes artifact: e60b831711 user: dgp
2006-04-06
19:14 • Ticket [1465666fff]: 4 changes artifact: 8429abf0ee user: dkf
11:47 • New ticket [1465666fff]. artifact: 850a1c016e user: afredd

8.5 lists sometimes uses more memory for 8.4..

Closed / Wont Fix1465666fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 20 years ago
Descriptionplain2006-04-06 11:47:48
Just stumbled across a case where 8.5 appears to use
more memory than 8.4 on windows.

The following loop builds a list and uses the *same*
amount of memory for both 8.4.8 and 8.5a4 on my
machine:

 set lst {}
 for {set i 0} {$i < 2000000} {incr i} {
  lappend lst $i
 }

(~56,800K for both versions.)

Now just sticking a dash in front of the $i
changes things:

 set lst {}
 for {set i 0} {$i < 2000000} {incr i} {
  lappend lst -$i
 }

Now 8.4.8 uses 96,100K to 8.5a4's 103,724K.
(In task manager there's a difference of 7K between
the Mem Usage, and a difference of 8K in the VM Size).
Both runs are done in fresh tclsh's.

Using different item elements brings back memory
usage parity eg. [lappend lst " $i "]
uses the same in both. Also ".$i" uses more in 8.5
, but "..$i" gives the same. Weird!

Is this additional memory usage due to a bug fix,
or an (un)?intended behaviour change?

Cheers.
dkf Ticket [1465666fff]: 4 changes [History diff]2006-04-06 19:14:41
dgpplain2006-06-21 03:40:31
Logged In: YES 
user_id=80530


something related to number
formating?
kennykbplain2006-06-21 20:37:56
Logged In: YES 
user_id=99768

I just tested this on my machine, and I get nearly identical
results between the two releases.  By contrast, I get
significantly different results between builds with and
without --enable-threads.  I expect this, since the threaded
allocator has somewhat higher overheads than the
non-threaded version.

Can you verify that the results of [parray tcl_platform] are
the same between your 8.4 and 8.5 builds?
kennykbplain2006-06-21 20:39:02
Logged In: YES 
user_id=99768

Changing status to 'Pending' and resolution to 'Works for
Me' - will reactivate if the original poster follows up.
afreddplain2006-06-21 21:50:16
Logged In: YES 
user_id=1386588

>Can you verify that the results of [parray tcl_platform]
>are the same between your 8.4 and 8.5 builds?

Both give:
% parray tcl_platform
tcl_platform(byteOrder) = littleEndian
tcl_platform(machine)   = intel
tcl_platform(os)        = Windows NT
tcl_platform(osVersion) = 5.1
tcl_platform(platform)  = windows
tcl_platform(user)      = afredd
tcl_platform(wordSize)  = 4
%

The 8.4.8 is a a ActiveState build. The 8.5a3 is a
home built version using VS6. Just reran the test
and get the original reported memory usage results.

However, with a home built 8.4.6 (don't have 8.4.8 to hand)
then this matches my 8.5a3. So the difference may be due
to the memory allocator used by the AS build. Does this
sound possible?

--

On a not quite tangent...
My original report came from trying to work out why
i was seeing timing differences in [lsort -real...]
where the list was of strings of "$i.".
I thought it might be due to some kind of memory overhead,
hence the report. But this was probably a red herring.

Been awhile since i've looked into this, but here's a
script you can try on 8.4 and 8.5 to see what i found:

proc main {} {
puts "Tcl [info patch]"
set max 1000
for {set j 1024} {1} {set j [expr {4 * $j}]} {
set lst {}
for {set i 0} {$i < $j} {incr i} {
lappend lst $i. ;# $i.$i ;# +$i -$i 
0 .$i
}
set N [llength $lst]
if {$N > 500000} break

set M [expr {2 + int(8000000.0 / ((log($N)) 
* $N))}]
if {$M > $max} { set M $max } ;# that's 
plenty!

lsort -real $lst ;# flush timing
puts "$N\t ($M)\t [lindex [time {lsort -
real $lst} $M] 0]"
}
}

main

# >%

And my results:

Tcl 8.5a3
1024     (1000)  567.529
4096     (236)   2700.5381355932204
16384    (52)    12117.807692307691
65536    (13)    57660.46153846154
262144   (4)     262260.5

Tcl 8.4.6
1024     (1000)  286
4096     (236)   1425
16384    (52)    6315
65536    (13)    30047
262144   (4)     132042

ie. 8.5 is significantly slower.
The seemingly obvious candidate is 8.5's new real number
parsing code... but when i looked into this closely i 
couldn't show this to be the case.

Can you replicate my timing differences?
dgpplain2006-06-22 02:02:15
Logged In: YES 
user_id=80530


Looks like a slowdown in
Tcl_GetDoubleFromObj().
There should be much less noise
in timing comparisons of this
in both releases:

time {binary format d 17.} 10000

I see change from ~13us to ~22us.
dgpplain2006-06-22 02:09:18
Logged In: YES 
user_id=80530


The slowdown appears to be
due to the addition of a 
check for the NaN value,
so an error can be raised when
that value is stored in the
Tcl_Obj.

It's been a matter of some
discussion how NaN values
ought to be handled, so this
may not be the final word on
the subject.
kennykbplain2007-01-03 22:49:39
Logged In: YES 
user_id=99768
Originator: NO

It is indeed true that Tcl_GetDoubleFromObj is slower on Windows in 8.5 than it was in 8.4 - but should be slower only when it actually has to shimmer a string.

It is also true that the old Tcl_GetDoubleFromObj fails dozens, if not hundreds, of the roundoff tests in expr-28.*.  To some extent, we appear to be facing a choice between "fast" and "correct."

Since the memory management appears to be exonerated, and since the performance change appears to be something that we've accepted for the moment, I'm closing out this issue.

A note to the original submitter.  Rather that using "$i." to convert an integer to floating point, it's both faster and safer to use [expr {double($i)}] -- and note the curly braces.  That won't trouble to generate a string representation of the 'double' until it's needed, and will do the integer-to-double conversion without going through an intermediate string representation.  In most of your examples, it will save both space and time.
dkf Ticket [1465666fff]: 1 change [History diff]2007-01-04 01:01:42
Log in (anonymous is fine) to add a comment.