Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Putting very large string into entry is very slow

58 views
Skip to first unread message

Alexandru

unread,
Oct 20, 2021, 11:49:14 AM10/20/21
to
Hi,

I just realized, that putting very large string into entry is very slow.

My string was 35k chars long. In my code I set the entry's variable to this string. The time needed to complete the action is the order of magnitude of 1 second.

pack [entry .e -textvariable ::myvar]
set s [join [lrepeat 35000 "a"] ""]
set ::myvar $s

Can you confirm this behavior?

Thanks
Alexandru

Ralf Fassel

unread,
Oct 20, 2021, 12:09:25 PM10/20/21
to
* Alexandru <alexandr...@meshparts.de>
| My string was 35k chars long. In my code I set the entry's variable to
| this string. The time needed to complete the action is the order of
| magnitude of 1 second.
>
| pack [entry .e -textvariable ::myvar]
| set s [join [lrepeat 35000 "a"] ""]
| set ::myvar $s
>
| Can you confirm this behavior?

No:
pack [entry .e -textvariable ::myvar]
update
set s [join [lrepeat 35000 "a"] ""]
(curious: why not simply 'string repeat'?)
time { set ::myvar $s }
=>
4579 microseconds per iteration

Note that if you run that interactively, the printing of the result string
to the console may take some time, too.

% info patchlevel
8.6.11
% parray tcl_platform
tcl_platform(byteOrder) = littleEndian
tcl_platform(engine) = Tcl
tcl_platform(machine) = x86_64
tcl_platform(os) = Linux
tcl_platform(osVersion) = 5.3.18-59.27-default
tcl_platform(pathSeparator) = :
tcl_platform(platform) = unix
tcl_platform(pointerSize) = 8
tcl_platform(threaded) = 1
tcl_platform(user) = ralf
tcl_platform(wordSize) = 8

R'

Rich

unread,
Oct 20, 2021, 2:13:51 PM10/20/21
to
Alexandru <alexandr...@meshparts.de> wrote:
> Hi,
>
> I just realized, that putting very large string into entry is very
> slow.
>
> My string was 35k chars long. In my code I set the entry's variable
> to this string. The time needed to complete the action is the order
> of magnitude of 1 second.

In addition to what Ralf indicated, is there some reason why you are
inserting such large strings into entries? An entry does not support
word wrap and attempting to actually use a display of a 35k character
string in an entry would be a UI nightmare.

An entry that contains a string longer than the width of the entry
itself begins to become a pain in the a** even if only a small part is
obscured. The longer the string, the bigger the pain. With 35k
characters, almost all characters of the string will be off one edge or
the other, and invisible.

Alexandru

unread,
Oct 20, 2021, 2:15:39 PM10/20/21
to
What is your OS?
I'm on Windows 10, 64 bit

Alexandru

unread,
Oct 20, 2021, 2:18:46 PM10/20/21
to
I already taken care of that. The long string is now cut if longer than 100 chars.
But still, I can think of another situation where this could happen.
The question is still, why it's so slow? Aside from any UI considerations.

Rich

unread,
Oct 20, 2021, 4:10:35 PM10/20/21
to
Alexandru <alexandr...@meshparts.de> wrote:
> Ralf Fassel schrieb am Mittwoch, 20. Oktober 2021 um 18:09:25 UTC+2:
>> * Alexandru <alexandr...@meshparts.de>
>> | My string was 35k chars long. ... In my code I set the entry's variable to
>> | this string. The time needed to complete the action is the order of
>> | magnitude of 1 second.
>> >
>> | Can you confirm this behavior?
>> No:
>> pack [entry .e -textvariable ::myvar]
>> update
>> set s [join [lrepeat 35000 "a"] ""]
>> (curious: why not simply 'string repeat'?)
>> time { set ::myvar $s }
>> =>
>> 4579 microseconds per iteration
>>
>> Note that if you run that interactively, the printing of the result
>> string to the console may take some time, too.
>>
>>
>> R'
> What is your OS?
> I'm on Windows 10, 64 bit

Were you using the Windows Tcl console (i.e., 'console show' from your
script)? And did you run your test commands above in that same
console?

If yes to both, then the time delay you saw was the console code
attempting to format the 35k character string for display. The Tcl
console that appears on windows from 'console show' (or from starting a
wish on windows) is quite slow dealing with large strings.

Rich

unread,
Oct 20, 2021, 4:11:23 PM10/20/21
to
See my other response asking if you were using the Tcl console window.

Alexandru

unread,
Oct 20, 2021, 4:39:48 PM10/20/21
to
I'm opening the console in advance and call a script using "source". There is no output to the console so that is not the reson. I'm aware that the console is slow on outputing long strings.

Rich

unread,
Oct 21, 2021, 12:08:10 AM10/21/21
to
The source command will return the last string output by the last
command in the file it sources. Have you shown us the exact script you
sourced? Because the script you /did/ show us most definitely outputs
a 35k character long string to the console.

Alexandru

unread,
Oct 21, 2021, 1:44:43 AM10/21/21
to
Here is script (but really, you can trust my ability to recognize a 35k chars long string being or not being output to the console):

pack [entry .e -textvariable ::myvar]
set s [join [lrepeat 35000 "a"] ""]
set ::myvar $s
return

Ralf Fassel

unread,
Oct 21, 2021, 5:32:14 AM10/21/21
to
* Alexandru <alexandr...@meshparts.de>
| Ralf Fassel schrieb am Mittwoch, 20. Oktober 2021 um 18:09:25 UTC+2:
--<snip-snip>--
| > tcl_platform(machine) = x86_64
| > tcl_platform(os) = Linux
| >
| > R'
| What is your OS?
| I'm on Windows 10, 64 bit

See above, Linux 64bit.

I get the same results on Windows:

% cat t.tcl
pack [entry .e -textvariable ::myvar]
set s [join [lrepeat 35000 "a"] ""]
set ::myvar $s
return
% wishpp
% time {source t.tcl}
11351 microseconds per iteration

% parray tcl_platform
tcl_platform(byteOrder) = littleEndian
tcl_platform(engine) = Tcl
tcl_platform(machine) = amd64
tcl_platform(os) = Windows NT
tcl_platform(osVersion) = 10.0
tcl_platform(pathSeparator) = ;
tcl_platform(platform) = windows
tcl_platform(pointerSize) = 8
tcl_platform(threaded) = 1
tcl_platform(user) = ralf
tcl_platform(wordSize) = 4

% info patchlevel
8.6.11

HTH
R'

Paul Obermeier

unread,
Oct 21, 2021, 5:46:04 AM10/21/21
to
Using Ralf's code above, I get 1811 microseconds on Windows8, 64-bit Tcl 8.6.10.
Paul

Alexandru

unread,
Oct 21, 2021, 6:14:13 AM10/21/21
to
I got it now.
Sorry one thing I did differently: I pack the entry in advance. Afterwards I execute the script:

set s [join [lrepeat 35000 "a"] ""]
set ::myvar $s

954877 microseconds per iteration

Interestigly. If I execute the script a second time, it's much faster:
2964 microseconds per iteration

Finally, if I delete the content of the entry and execute the script, than it's slow again.

Uwe Klein

unread,
Oct 21, 2021, 7:13:10 AM10/21/21
to
Am 20.10.21 um 20:18 schrieb Alexandru:
> I already taken care of that. The long string is now cut if longer than 100 chars.
> But still, I can think of another situation where this could happen.
> The question is still, why it's so slow? Aside from any UI considerations.
>
cascading realloc to accomodate the string?

Uwe

Ralf Fassel

unread,
Oct 21, 2021, 12:57:51 PM10/21/21
to
* Paul Obermeier <ober...@poSoft.de>
--<snip-snip>--
| > % wishpp
| > % time {source t.tcl}
| > 11351 microseconds per iteration
--<snip-snip>--
>
| Using Ralf's code above, I get 1811 microseconds on Windows8, 64-bit Tcl 8.6.10.

Yeah, my 'jupiter' is a 2012 core-i5, not the greatest rocket nowadays :-)))

R'
0 new messages