Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Unix will self-destruct in five seconds... 4... 3... 2... 1...


devel / comp.lang.tcl / Re: Inserting thousands of images in a text widget - too slow

SubjectAuthor
* Inserting thousands of images in a text widget - too slowLuc
+- Inserting thousands of images in a text widget - too slowHelmut Giese
`* Inserting thousands of images in a text widget - too slowRich
 `* Inserting thousands of images in a text widget - too slowLuc
  `* Inserting thousands of images in a text widget - too slowRich
   +* Inserting thousands of images in a text widget - too slowLuc
   |`* Inserting thousands of images in a text widget - too slowRich
   | `* Inserting thousands of images in a text widget - too slowLuc
   |  `* Inserting thousands of images in a text widget - too slowRich
   |   `* Inserting thousands of images in a text widget - too slowLuc
   |    +* Inserting thousands of images in a text widget - too slowLuc
   |    |+* Inserting thousands of images in a text widget - too slowRich
   |    ||`- Inserting thousands of images in a text widget - too slowLuc
   |    |`- Inserting thousands of images in a text widget - too slowet99
   |    `* Inserting thousands of images in a text widget - too slowRich
   |     `* Inserting thousands of images in a text widget - too slowLuc
   |      `* Inserting thousands of images in a text widget - too slowRich
   |       `- Inserting thousands of images in a text widget - too slowLuc
   `- Inserting thousands of images in a text widget - too slowLuc

1
Inserting thousands of images in a text widget - too slow

<20231229142620.140d719b@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12664&group=comp.lang.tcl#12664

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc...@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: Inserting thousands of images in a text widget - too slow
Date: Fri, 29 Dec 2023 14:26:20 -0300
Organization: A noiseless patient Spider
Lines: 89
Message-ID: <20231229142620.140d719b@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="d26812a1fb9aeb389785a782d754d2b5";
logging-data="956722"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19VyA+YCB1tCKmMdGR0zFAKwt3xMc+Os4E="
Cancel-Lock: sha1:WNjR2lHPTgJACudHPmvjk0b7WWk=
 by: Luc - Fri, 29 Dec 2023 17:26 UTC

First, I do this:

proc p0.StartUp.SetUpIcons {} {
set ::BaseVars_WindowIconFile "$::BaseVars_iconsdir/eye5.png"
set ::BaseVars_WindowIconFile [image create photo -file $::BaseVars_WindowIconFile]
wm iconphoto . -default $::BaseVars_WindowIconFile

load "$::BaseVars_iconsdir/libtksvg0.12.so"
set ::CustomVars_IconFile_Dir_Close "$::BaseVars_iconsdir/folder_closed3.svg"
set ::CustomVars_IconFile_Dir_Open "$::BaseVars_iconsdir/folder_open3.svg"
set ::CustomVars_IconFile_CommonFile "$::BaseVars_iconsdir/file_black.svg"
set ::CustomVars_IconFile_Skinny "$::BaseVars_iconsdir/skinny.svg"
set iconsize $::GUIoptions_IconSize
set ::CustomVars_Image_IconFile_Dir_Close \
[image create photo ::CustomVars_IconFile_Dir_Close -file "$::CustomVars_IconFile_Dir_Close" -format "svg -scaletoheight $iconsize"]
set ::CustomVars_Image_IconFile_Dir_Open \
[image create photo ::CustomVars_IconFile_Dir_Open -file "$::CustomVars_IconFile_Dir_Open" -format "svg -scaletoheight $iconsize"]
set ::CustomVars_Image_IconFile_CommonFile \
[image create photo ::CustomVars_IconFile_CommonFile -file $::CustomVars_IconFile_CommonFile -format "svg -scaletoheight $iconsize"]
set ::CustomVars_Image_IconFile_Skinny \
[image create photo ::CustomVars_IconFile_Skinny -file $::CustomVars_IconFile_Skinny -format "svg -scaletoheight $iconsize"]
}

There is also this relevant proc:

p.GUI.InsertCorrectIcon {widget type target}

It's long and tedious, let's see just one part of it, it should
be enough:

if {$type == "typedir"} {
if {[file exists $::CustomVars_IconFile_Dir_Close]} {
$widget image create end -image $::CustomVars_Image_IconFile_Dir_Close
$widget insert end { }
} else {$widget insert end {D}}
return
}

OK. Then later on I build boxes with a file listing:

foreach line $organizedlist {
set insw $::Widgets_unipane.fileListPane.filenameframe.box
p.GUI.InsertCorrectIcon $insw [lindex $line 0] [lindex $line 1]
$insw insert end "[lindex $line 1]\n"
set insw $::Widgets_unipane.fileListPane.sizeframe.box
p.GUI.InsertCorrectIcon $insw [lindex $line 0] "___!SKINNY_ICON!___"
$insw insert end "[p.Utils.FormatUnits [lindex $line 2]]\n"
set insw $::Widgets_unipane.fileListPane.dateframe.box
p.GUI.InsertCorrectIcon $insw [lindex $line 0] "___!SKINNY_ICON!___"
$insw insert end "[clock format [lindex $line 3] -format "%Y-%m-%d %H:%M:%S"]\n"
set insw $::Widgets_unipane.fileListPane.permissionframe.box
p.GUI.InsertCorrectIcon $insw [lindex $line 0] "___!SKINNY_ICON!___"
$insw insert end "[p.Utils.Deoctalize [lindex $line 4]]\n"
set insw $::Widgets_unipane.fileListPane.ownerframe.box
p.GUI.InsertCorrectIcon $insw [lindex $line 0] "___!SKINNY_ICON!___"
$insw insert end "[lindex $line 5]\n"
}

And it all seemed to work so well until I "opened" a large directory.
Then it all gets pretty ugly.

For example, I have this directory with 3,000 items. My application
takes 5 seconds to "load" that directory. The delay is quite noticeable.

And it gets worse. I have another directory inside ~/Mail, one of my
oldest email accounts, with 12,500 items. My application takes a full
minute to load that directory. For comparison, SpaceFM takes 8 seconds
and PCManFM takes 3 seconds.

My application can load that huge directory almost instantaneously if I
disable the icons. It's clear the icons slow everything down. Badly.
But they are important aesthetically.

Is there some way around this problem? Can I make it faster?

Much, much faster?

--
Luc
>>

Re: Inserting thousands of images in a text widget - too slow

<kd2uoi16g3d5gcv5g4mn7vlfhsonfmbk6t@4ax.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12665&group=comp.lang.tcl#12665

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgi...@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Fri, 29 Dec 2023 19:09:58 +0100
Organization: ratiosoft
Lines: 14
Message-ID: <kd2uoi16g3d5gcv5g4mn7vlfhsonfmbk6t@4ax.com>
References: <20231229142620.140d719b@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="239d81896e957875a4d0f24af3d72e20";
logging-data="982351"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/YSgWU8fvyHFDj2ucc0oms"
Cancel-Lock: sha1:CZjTf4/xbZMEoxqyMRMTOl3eGrI=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
 by: Helmut Giese - Fri, 29 Dec 2023 18:09 UTC

Hi Luc,
>My application can load that huge directory almost instantaneously if I
>disable the icons. It's clear the icons slow everything down. Badly.
>But they are important aesthetically.
>
>Is there some way around this problem? Can I make it faster?
>
>Much, much faster?
one way is to load just as many icons as are visible at one moment
(maybe plus a few more so that the user can scroll already while you
load the next 'page'). And I would create a 'dict' holding one key for
every entry in your directory to remember any icon already loaded.
Good luck
Helmut

Re: Inserting thousands of images in a text widget - too slow

<umoaei$16gr4$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12668&group=comp.lang.tcl#12668

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Sat, 30 Dec 2023 05:39:30 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <umoaei$16gr4$1@dont-email.me>
References: <20231229142620.140d719b@lud1.home>
Injection-Date: Sat, 30 Dec 2023 05:39:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bb4466b9a5eee03458acbf33d0558aaa";
logging-data="1262436"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ZpnlfaF6R0tN8onggYFW3"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:/DqrdyG8vyCxFFYsUpeX0Bm92MI=
 by: Rich - Sat, 30 Dec 2023 05:39 UTC

Luc <luc@sep.invalid> wrote:
>
> And it gets worse. I have another directory inside ~/Mail, one of my
> oldest email accounts, with 12,500 items. My application takes a
> full minute to load that directory. For comparison, SpaceFM takes 8
> seconds and PCManFM takes 3 seconds.
>
> My application can load that huge directory almost instantaneously if I
> disable the icons. It's clear the icons slow everything down. Badly.
> But they are important aesthetically.

You didn't need all that complicated code here. You needed to digest
it down to an example case, like so:

#!/usr/bin/wish

image create photo IMAGE -file /usr/share/icons/hicolor/32x32/apps/kicad.png

text .t
pack .t

set begin [clock milliseconds]
for {set i 0} {$i < 12500} {incr i} {
.t insert end "$i: "
.t image create end -image IMAGE
.t insert end ":$i\n"
}

#make sure work to actually display is complete
update

set end [clock milliseconds]
puts "[expr {$end - $begin}] ms elapsed"

The above is what I mean when I tell you to post "working code" -- and
additionally: "easy to understand code". Compare the understandability
of the above to what you posted. Note, if you don't have a "kicad.png"
then substitute another png icon in /usr/share/icons/hicolor/32x32/
that you *do* have.

Running the above on my machine, I get:

11149 ms elapsed

If I comment out the "image create" call, I get:

123 ms elapsed

> Is there some way around this problem?

Nothing that will be simple, as this looks to be a slowness within the
text widget itself. So short of posting a patch to the C code of the
text widget to remove what looks like an O(n^2) complexity factor when
inserting images there is not a whole lot you can do.

> Can I make it faster?

Possibly, but you'd have to setup a system where you fill out the
widget with text, without images, then insert the images just before
lines scroll into view, avoiding the need to "create" everything up
front.

> Much, much faster?

Avoid images or use Unicode characters that are the same, or close
enough, to your current images as substitutes for the images you
currently use.

Re: Inserting thousands of images in a text widget - too slow

<20231230181414.458f441d@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12671&group=comp.lang.tcl#12671

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc...@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Sat, 30 Dec 2023 18:14:14 -0300
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <20231230181414.458f441d@lud1.home>
References: <20231229142620.140d719b@lud1.home>
<umoaei$16gr4$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: dont-email.me; posting-host="098b9560f4098189303e24210b9f2f65";
logging-data="1485591"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18XreTBXnGPRWJRZ2PCRmwBmOoPwWX2Y/o="
Cancel-Lock: sha1:GfhwDLzHl4/E2v0SwOJgVr8G4jQ=
 by: Luc - Sat, 30 Dec 2023 21:14 UTC

On Sat, 30 Dec 2023 05:39:30 -0000 (UTC), Rich wrote:

>You didn't need all that complicated code here.

I thought I should because you always ask for code and because I had
done it in a different way that was even slower, then I found the
current way which is a lot faster and maybe I could still be doing
something wrong or stupid.

>Avoid images or use Unicode characters that are the same, or close
>enough, to your current images as substitutes for the images you
>currently use.

I thought about using Unicode and I think that would be great although
too many users would disagree and demand custom iconsets. But alas,
the only Unicode characters I could find that would satisfactorily
represent files and folders are out of Tcl/Tk's reach, such as

1F5C0 🗀 1F5C1 🗁 1F4BC 💼 1F5B9 🖹 1F4C4 📄

TK can't display those.

I wonder if they are going to make it through intact here. Let's see.

--
Luc
>>

Re: Inserting thousands of images in a text widget - too slow

<umqca4$1eokp$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12675&group=comp.lang.tcl#12675

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.chmurka.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Sun, 31 Dec 2023 00:23:33 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <umqca4$1eokp$1@dont-email.me>
References: <20231229142620.140d719b@lud1.home> <umoaei$16gr4$1@dont-email.me> <20231230181414.458f441d@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 31 Dec 2023 00:23:33 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c5b93b05d01422acbf560bfc0da07fb3";
logging-data="1532569"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19NPQMOVmjSjxpkyjxZbmND"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:/1q31X95J6UOzhQPzzknZfWvKWs=
 by: Rich - Sun, 31 Dec 2023 00:23 UTC

Luc <luc@sep.invalid> wrote:
> On Sat, 30 Dec 2023 05:39:30 -0000 (UTC), Rich wrote:
>
>>You didn't need all that complicated code here.
>
> I thought I should because you always ask for code and because I had
> done it in a different way that was even slower, then I found the
> current way which is a lot faster and maybe I could still be doing
> something wrong or stupid.

Code that demonstrates the issue. Not "a chunk of your project's
code". The difference is significant, and important.

>>Avoid images or use Unicode characters that are the same, or close
>>enough, to your current images as substitutes for the images you
>>currently use.
>
> I thought about using Unicode and I think that would be great although
> too many users would disagree and demand custom iconsets.

If you are going to allow for user custom icon sets then that means
some trickery to work around the issue. One option might be to build a
"virtual scrolling" setup where your text widget only has the number of
lines visible on screen, plus some small amount, and you "scroll" up
and down by replacing lines in the widget rather than by scrolling a
widget with 12,500 lines.

> But alas, the only Unicode characters I could find that would
> satisfactorily represent files and folders are out of Tcl/Tk's reach,
> such as
>
> 1F5C0 🗀 1F5C1 🗁 1F4BC 💼 1F5B9 🖹 1F4C4 📄
>
> TK can't display those.

Tcl 9 should correct that (as far as I understand). But that does not
help you now.

> I wonder if they are going to make it through intact here. Let's see.

No, I got blank boxes here as well.

Re: Inserting thousands of images in a text widget - too slow

<20231230215329.243c26f2@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12676&group=comp.lang.tcl#12676

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc...@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Sat, 30 Dec 2023 21:53:29 -0300
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <20231230215329.243c26f2@lud1.home>
References: <20231229142620.140d719b@lud1.home>
<umoaei$16gr4$1@dont-email.me>
<20231230181414.458f441d@lud1.home>
<umqca4$1eokp$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: dont-email.me; posting-host="268b47be7199f8e9df5fffd05ffb3497";
logging-data="1538380"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+SHqv39OMulvwwRu74PJKCOGoakA5eHvs="
Cancel-Lock: sha1:dqAr29Xoqo1XuppT/AeqLTZb0E0=
 by: Luc - Sun, 31 Dec 2023 00:53 UTC

On Sun, 31 Dec 2023 00:23:33 -0000 (UTC), Rich wrote:

>If you are going to allow for user custom icon sets then that means
>some trickery to work around the issue.

I think the problem is in 'image create'. That already sounds like
heavy work. Done thousands of times, it can't be fast.

I wish there was some way we could create an image once and "cache" it
then use it like a rubberstamp without having to "create" it every
single time. I've been trying to figure out some way to do that or to
turn everything into one single huge string to be inserted in one fell
swoop, but there doesn't seem to be a way. :-(

>> 1F5C0 🗀 1F5C1 🗁 1F4BC 💼 1F5B9 🖹 1F4C4 📄
>> TK can't display those.

>Tcl 9 should correct that (as far as I understand). But that does not
>help you now.
>> I wonder if they are going to make it through intact here. Let's see.
>
>No, I got blank boxes here as well.

"As well"? Must be your email/news reader. They all got through intact
for me. And the version of email reader I'm using was released seven
years ago.

--
Luc
>>

Re: Inserting thousands of images in a text widget - too slow

<20231230220155.620513ec@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12677&group=comp.lang.tcl#12677

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc...@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Sat, 30 Dec 2023 22:01:55 -0300
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <20231230220155.620513ec@lud1.home>
References: <20231229142620.140d719b@lud1.home>
<umoaei$16gr4$1@dont-email.me>
<20231230181414.458f441d@lud1.home>
<umqca4$1eokp$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="268b47be7199f8e9df5fffd05ffb3497";
logging-data="1541063"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+O3WULwP67GDnqg7Ot9xukRXCmnalv+8="
Cancel-Lock: sha1:muar0+eJnx7qLG6XLlwouoA2Qf0=
 by: Luc - Sun, 31 Dec 2023 01:01 UTC

On Sun, 31 Dec 2023 00:23:33 -0000 (UTC), Rich wrote:

>If you are going to allow for user custom icon sets then that means
>some trickery to work around the issue. One option might be to build a
>"virtual scrolling" setup where your text widget only has the number of
>lines visible on screen, plus some small amount, and you "scroll" up
>and down by replacing lines in the widget rather than by scrolling a
>widget with 12,500 lines.

I've thought about that, but it seems too hard. "Scrolling" means a lot
of things. Maybe the user will use arrow keys. Maybe PageUp/PageDown.
Maybe the mouse wheel. Maybe Home/End to jump to the beginning and end.
And there is selection. Maybe it's a long selection that extends beyond
the limits of the fake view.

Imagine managing all that. That alone will cost me more work than the
entire application. I don't think I want to afford that.

I will sooner scrap the text widget model for buttons or labels or
something else. I don't know. This is one heck of a show-stopper.

--
Luc
>>

Re: Inserting thousands of images in a text widget - too slow

<umqidb$1fcdk$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12678&group=comp.lang.tcl#12678

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Sun, 31 Dec 2023 02:07:39 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <umqidb$1fcdk$1@dont-email.me>
References: <20231229142620.140d719b@lud1.home> <umoaei$16gr4$1@dont-email.me> <20231230181414.458f441d@lud1.home> <umqca4$1eokp$1@dont-email.me> <20231230215329.243c26f2@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 31 Dec 2023 02:07:39 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c5b93b05d01422acbf560bfc0da07fb3";
logging-data="1552820"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/pA0UZmuoLtPguZUunRM9p"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:OCVSy8ySegE5S26/LhHlWPWi5pE=
 by: Rich - Sun, 31 Dec 2023 02:07 UTC

Luc <luc@sep.invalid> wrote:
> On Sun, 31 Dec 2023 00:23:33 -0000 (UTC), Rich wrote:
>
>>If you are going to allow for user custom icon sets then that means
>>some trickery to work around the issue.
>
> I think the problem is in 'image create'. That already sounds like
> heavy work. Done thousands of times, it can't be fast.
>
> I wish there was some way we could create an image once and "cache" it

You already do that (and my short example does as well). The "image"
is only created once, in this line:

image create photo IMAGE -file /usr/share/icons/hicolor/32x32/apps/kicad.png

The text widget is reusing that same image over and over. But
somewhere in the code for the text widget is some code that expends
ever more time for each new image created within the text (for the text
widget, 'image create' is not creating a new image, it is creating a
new image annotation within the text).

Given the slowdown, it feels like an algorithm that is doing something
like measuring the height of every prior line already in the widget for
each new image that is inserted. Doing something like that would lead
to the amount of slowdown seen. Note that I don't know what is causing
the excessive work, just guessing at one possibility.

> then use it like a rubberstamp without having to "create" it every
> single time. I've been trying to figure out some way to do that or to
> turn everything into one single huge string to be inserted in one fell
> swoop, but there doesn't seem to be a way. :-(

Right now, given the slowdown seen, working out a way to not have to
insert so many images, almost all of which won't be visible on screen
unless the user scrolls, will probably be the way to go.

>>> 1F5C0 🗀 1F5C1 🗁 1F4BC 💼 1F5B9 🖹 1F4C4 📄
>>
>>No, I got blank boxes here as well.
>
> "As well"? Must be your email/news reader. They all got through intact
> for me. And the version of email reader I'm using was released seven
> years ago.

It is also possible that the font I'm using simply does not have glyphs
for those codepoints.

Re: Inserting thousands of images in a text widget - too slow

<20231231011828.38444f56@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12679&group=comp.lang.tcl#12679

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc...@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Sun, 31 Dec 2023 01:18:28 -0300
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <20231231011828.38444f56@lud1.home>
References: <20231229142620.140d719b@lud1.home>
<umoaei$16gr4$1@dont-email.me>
<20231230181414.458f441d@lud1.home>
<umqca4$1eokp$1@dont-email.me>
<20231230215329.243c26f2@lud1.home>
<umqidb$1fcdk$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="268b47be7199f8e9df5fffd05ffb3497";
logging-data="1718287"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX185m8qiOL1Gls3oBBa+W9soiFqwTHw0qr4="
Cancel-Lock: sha1:VpcwD3WwEAvhafTWQv4MoQZuz5o=
 by: Luc - Sun, 31 Dec 2023 04:18 UTC

Just for the record, I can fill up a text widget with 20,000 buttons
with both text and image in under 500 ms.

How can buttons be so fast, even with images?

I also tried filling it up with labels and with other one-line text
widgets. Those were much, much too slow. And I didn't even try them
with images.

I don't think I can really use buttons though. I suspect they will be
too clumsy for my purposes.

Back to the drawing board...

package require Tk
wm withdraw .
set w [toplevel .top]

set wf [frame $w.frame]
pack $wf -fill both -expand 1

set sb [scrollbar $wf.sb -orient vertical -command "$w.tx yview"]
set tx [text $wf.tx -font {Arial 14} -yscrollcommand [list $sb set]]
$sb configure -command [list $tx yview]]
pack $sb -fill y -side right
pack $tx -fill both -expand 1
focus $tx
bind .top <Escape> {exit 0}

set begin [clock milliseconds]
image create photo IMAGE -file /usr/share/icons/hicolor/32x32/apps/elk.png
for {set x 1} {$x <= 20000} {incr x} {
button $tx.b$x -text $x -width 80 -cursor arrow -image IMAGE -compound left
pack $tx.b$x
$tx window create end -window $tx.b$x
$tx insert end "\n"
} set end [clock milliseconds]
puts "[expr {$end - $begin}] ms elapsed"

--
Luc
>>

Re: Inserting thousands of images in a text widget - too slow

<ums6a7$1po0r$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12680&group=comp.lang.tcl#12680

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Sun, 31 Dec 2023 16:53:28 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <ums6a7$1po0r$1@dont-email.me>
References: <20231229142620.140d719b@lud1.home> <umoaei$16gr4$1@dont-email.me> <20231230181414.458f441d@lud1.home> <umqca4$1eokp$1@dont-email.me> <20231230215329.243c26f2@lud1.home> <umqidb$1fcdk$1@dont-email.me> <20231231011828.38444f56@lud1.home>
Injection-Date: Sun, 31 Dec 2023 16:53:28 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c5b93b05d01422acbf560bfc0da07fb3";
logging-data="1892379"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/onxeRF2MhrDRS96vS6DNq"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:jQr2uhOsjEyZsrKnJluUkguedro=
 by: Rich - Sun, 31 Dec 2023 16:53 UTC

Luc <luc@sep.invalid> wrote:
> Just for the record, I can fill up a text widget with 20,000 buttons
> with both text and image in under 500 ms.

I get 502ms for my last run, which had two mods:

button $tx.b$x -text $x -width 80 -cursor arrow -image IMAGE -compound l
#pack $tx.b$x
$tx insert end "$x "
$tx window create end -window $tx.b$x
$tx insert end "$x\n"

Widgets that you plan to "insert" into a text widget do not need to be
packed (packing is for display within a frame or toplevel, not for
inside another widget).

And I added text in front and behind (just in case that made any
difference). It did not seem to.

> How can buttons be so fast, even with images?

Simple. The code path used for "window create" is different from the
code path used for "image create" and the "window create" code path
does not have the O(n^2) algorithm within it.

> I also tried filling it up with labels and with other one-line text
> widgets. Those were much, much too slow. And I didn't even try them
> with images.

Ok, so a way around the "slow images" is to use buttons containing
images.

> I don't think I can really use buttons though. I suspect they will be
> too clumsy for my purposes.

Why? You can make them into "nothing windows" (remove all bindings,
turn off all decorations) such that they don't change or push or do
anything. Beyond a bit of "manual memory management" (you'll want to
either reuse existing buttons for destroy/recreate them as needed) they
do solve your performance problem with regular image create in a text.

> Back to the drawing board...

Why, it seems you've found an excellent workaround. The complexity
here (tracking your "image buttons" for memory management purposes) is
significantly lower than building up a "virtual scrolling" system.

Meanwhile you might also consider filing a bug report on the text
widget performance with image create (and now that you've discovered
the "image in a button" workaround, you have further evidence that the
issue is not directly related to "images" themselves, but something
different between "image create" and "window create").

Re: Inserting thousands of images in a text widget - too slow

<20231231142543.77bb94c4@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12681&group=comp.lang.tcl#12681

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc...@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Sun, 31 Dec 2023 14:25:43 -0300
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <20231231142543.77bb94c4@lud1.home>
References: <20231229142620.140d719b@lud1.home>
<umoaei$16gr4$1@dont-email.me>
<20231230181414.458f441d@lud1.home>
<umqca4$1eokp$1@dont-email.me>
<20231230215329.243c26f2@lud1.home>
<umqidb$1fcdk$1@dont-email.me>
<20231231011828.38444f56@lud1.home>
<ums6a7$1po0r$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="4d62022a5564bd632264e26a6e1164ac";
logging-data="1898641"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+E6Lp2mbHeGFZhztzMkBFktsxNUbBHSJs="
Cancel-Lock: sha1:52huBXgFLOw+inp8sYpiEsasmwU=
 by: Luc - Sun, 31 Dec 2023 17:25 UTC

On Sun, 31 Dec 2023 16:53:28 -0000 (UTC), Rich wrote:

>Ok, so a way around the "slow images" is to use buttons containing
>images.
>
>Why, it seems you've found an excellent workaround.

Meh. Not so fast.

The code I posted never changes the font. As soon as I specify a font,
the whole thing becomes slower by a factor of 70x!

Back to the drawing board...

--
Luc
>>

Re: Inserting thousands of images in a text widget - too slow

<20231231161455.1a2d8f4a@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12682&group=comp.lang.tcl#12682

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc...@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Sun, 31 Dec 2023 16:14:55 -0300
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <20231231161455.1a2d8f4a@lud1.home>
References: <20231229142620.140d719b@lud1.home>
<umoaei$16gr4$1@dont-email.me>
<20231230181414.458f441d@lud1.home>
<umqca4$1eokp$1@dont-email.me>
<20231230215329.243c26f2@lud1.home>
<umqidb$1fcdk$1@dont-email.me>
<20231231011828.38444f56@lud1.home>
<ums6a7$1po0r$1@dont-email.me>
<20231231142543.77bb94c4@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="4d62022a5564bd632264e26a6e1164ac";
logging-data="1926116"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+77nm3BdBCx1GDWK3V20U7eX6SQP0pfPs="
Cancel-Lock: sha1:InLIxTpMxUk1lx1WoYoCHGBJa8o=
 by: Luc - Sun, 31 Dec 2023 19:14 UTC

Greetings from the drawing board.

My threaded version of the thing I'm working on is actually slower than
the previous design.

I still struggle to understand threads so maybe I did something wrong.

Or maybe threads won't help in this case. What do you think?

--------------------
package require Tk
package require Thread

image create photo IMAGE -file /usr/share/icons/hicolor/32x32/apps/elk.png

text .t -font {Freesans 14}
pack .t
focus .t
bind .t <Escape> {exit 0}

set begin [clock milliseconds]

set linecount 4500
set chunksize 1500
set chunks [dict create]
for {set x 1} {$x <= $linecount} {incr x} {
set y [expr {$x - 1}]
if {![info exists chunkstart$x] && ![info exists chunkstart1]} {
set chunkstart$x 1
} else {set chunkstart$x [expr {[set chunkend$y] + 1}]}
set chunkend$x [expr {[set chunkstart$x] + [expr {$chunksize - 1}]}]
if {[set chunkend$x] >= $linecount} {set chunkend$x $linecount}
dict set chunks chunk$x "start [set chunkstart$x] end [set chunkend$x]"
if {[set chunkend$x] >= $linecount} {break}
}

# confirming that the chunks are alright
#foreach ch [dict keys $chunks] {puts "$ch starts at [dict get $chunks $ch "start"]\n$ch ends at [dict get $chunks $ch "end"]\n"}

# create all the empty lines first
for {set i 1} {$i <= $linecount} {incr i} {
.t insert end " line$i\n"
} proc populate {} {
foreach ch [dict keys $::chunks] {
for {set x [dict get $::chunks $ch "start"]} {$x <= [dict get $::chunks $ch "end"]} {incr x} {
.t image create $x.0 -image IMAGE
}
}
} foreach chunk [dict keys $chunks] {
set tid_$chunk [thread::create {thread::wait}]
unset -nocomplain resultof_$chunk
thread::send -async [set tid_$chunk] [populate] resultof_$chunk
if {![info exist resultof_$chunk]} {vwait resultof_$chunk}
}

update
set end [clock milliseconds]

focus .t
..t see end
puts "[expr {$end - $begin}] ms elapsed"
--------------------

--
Luc
>>

Re: Inserting thousands of images in a text widget - too slow

<umshl4$1r78o$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12683&group=comp.lang.tcl#12683

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Sun, 31 Dec 2023 20:07:00 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <umshl4$1r78o$1@dont-email.me>
References: <20231229142620.140d719b@lud1.home> <umoaei$16gr4$1@dont-email.me> <20231230181414.458f441d@lud1.home> <umqca4$1eokp$1@dont-email.me> <20231230215329.243c26f2@lud1.home> <umqidb$1fcdk$1@dont-email.me> <20231231011828.38444f56@lud1.home> <ums6a7$1po0r$1@dont-email.me> <20231231142543.77bb94c4@lud1.home>
Injection-Date: Sun, 31 Dec 2023 20:07:00 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c5b93b05d01422acbf560bfc0da07fb3";
logging-data="1940760"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ycPkSeXC6jVmzGi2qHzG0"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:Xv2vW4dHqo0QgLYyyAzHBwG83kI=
 by: Rich - Sun, 31 Dec 2023 20:07 UTC

Luc <luc@sep.invalid> wrote:
> On Sun, 31 Dec 2023 16:53:28 -0000 (UTC), Rich wrote:
>
>>Ok, so a way around the "slow images" is to use buttons containing
>>images.
>>
>>Why, it seems you've found an excellent workaround.
>
>
> Meh. Not so fast.
>
> The code I posted never changes the font. As soon as I specify a font,
> the whole thing becomes slower by a factor of 70x!

How did you specify the font?

Re: Inserting thousands of images in a text widget - too slow

<umshoo$1r78o$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12684&group=comp.lang.tcl#12684

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Sun, 31 Dec 2023 20:08:57 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <umshoo$1r78o$2@dont-email.me>
References: <20231229142620.140d719b@lud1.home> <umoaei$16gr4$1@dont-email.me> <20231230181414.458f441d@lud1.home> <umqca4$1eokp$1@dont-email.me> <20231230215329.243c26f2@lud1.home> <umqidb$1fcdk$1@dont-email.me> <20231231011828.38444f56@lud1.home> <ums6a7$1po0r$1@dont-email.me> <20231231142543.77bb94c4@lud1.home> <20231231161455.1a2d8f4a@lud1.home>
Injection-Date: Sun, 31 Dec 2023 20:08:57 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c5b93b05d01422acbf560bfc0da07fb3";
logging-data="1940760"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7/91uuS/k6PZja1y1GZ0B"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:c6ewyh0csG37ohgbEQbMGsWAU5c=
 by: Rich - Sun, 31 Dec 2023 20:08 UTC

Luc <luc@sep.invalid> wrote:
> Greetings from the drawing board.
>
> My threaded version of the thing I'm working on is actually slower than
> the previous design.
>
> I still struggle to understand threads so maybe I did something wrong.
>
> Or maybe threads won't help in this case. What do you think?

Threads won't help. The reason why is the slowness is from the code of
the single text widget that is doing the display of all the lines.

No matter how many threads you launch, they all end up serialized on
that one single text widget, that is doing all the work of formatting
the display data. And the slowdown is somewhere inside the code that
does the "formatting for display".

Re: Inserting thousands of images in a text widget - too slow

<20231231174858.7ae4501d@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12685&group=comp.lang.tcl#12685

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc...@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Sun, 31 Dec 2023 17:48:58 -0300
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <20231231174858.7ae4501d@lud1.home>
References: <20231229142620.140d719b@lud1.home>
<umoaei$16gr4$1@dont-email.me>
<20231230181414.458f441d@lud1.home>
<umqca4$1eokp$1@dont-email.me>
<20231230215329.243c26f2@lud1.home>
<umqidb$1fcdk$1@dont-email.me>
<20231231011828.38444f56@lud1.home>
<ums6a7$1po0r$1@dont-email.me>
<20231231142543.77bb94c4@lud1.home>
<umshl4$1r78o$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="4d62022a5564bd632264e26a6e1164ac";
logging-data="1948721"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19aHVrdOzt641mgBfJBWhzGz/2Him8ktyY="
Cancel-Lock: sha1:VTOIDapNeoc3XX52ry0dZSn3J6o=
 by: Luc - Sun, 31 Dec 2023 20:48 UTC

On Sun, 31 Dec 2023 20:07:00 -0000 (UTC), Rich wrote:

>Luc <luc@sep.invalid> wrote:
>> On Sun, 31 Dec 2023 16:53:28 -0000 (UTC), Rich wrote:
>>
>>>Ok, so a way around the "slow images" is to use buttons containing
>>>images.
>>>
>>>Why, it seems you've found an excellent workaround.
>>
>>
>> Meh. Not so fast.
>>
>> The code I posted never changes the font. As soon as I specify a font,
>> the whole thing becomes slower by a factor of 70x!
>
>How did you specify the font?
>
**************************

The same code I posted yesterday. It specifies a font for the text
widget that contains everything.

438 ms

I realized the text widget is just a container and doesn't need any
specific font. So I removed it.

440 ms

Then I added the font specification to the line that creates the button:

button $tx.b$x -font {Arial 14} -text $x -width 80 -cursor arrow -image IMAGE -compound left

76111 ms

Yikes.

--
Luc
>>

Re: Inserting thousands of images in a text widget - too slow

<20231231184212.661dd969@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12686&group=comp.lang.tcl#12686

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc...@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Sun, 31 Dec 2023 18:42:12 -0300
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <20231231184212.661dd969@lud1.home>
References: <20231229142620.140d719b@lud1.home>
<umoaei$16gr4$1@dont-email.me>
<20231230181414.458f441d@lud1.home>
<umqca4$1eokp$1@dont-email.me>
<20231230215329.243c26f2@lud1.home>
<umqidb$1fcdk$1@dont-email.me>
<20231231011828.38444f56@lud1.home>
<ums6a7$1po0r$1@dont-email.me>
<20231231142543.77bb94c4@lud1.home>
<20231231161455.1a2d8f4a@lud1.home>
<umshoo$1r78o$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="4d62022a5564bd632264e26a6e1164ac";
logging-data="1963315"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3Mwm68nDGSD6uqzFXkiQo47kVM/T6M+U="
Cancel-Lock: sha1:S/fgh4tIg+QimDKQDsHfxiwofYI=
 by: Luc - Sun, 31 Dec 2023 21:42 UTC

On Sun, 31 Dec 2023 20:08:57 -0000 (UTC), Rich wrote:

>Threads won't help. The reason why is the slowness is from the code of
>the single text widget that is doing the display of all the lines.
>
>No matter how many threads you launch, they all end up serialized on
>that one single text widget, that is doing all the work of formatting
>the display data. And the slowdown is somewhere inside the code that
>does the "formatting for display".
**************************

Threads will help if they give me a responsive GUI while the application
does something else behind the curtains. The way I did it, it is not
responsive until all the threads have finished their tasks.

--
Luc
>>

Re: Inserting thousands of images in a text widget - too slow

<umsta9$1slld$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12688&group=comp.lang.tcl#12688

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et9...@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Sun, 31 Dec 2023 15:25:59 -0800
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <umsta9$1slld$1@dont-email.me>
References: <20231229142620.140d719b@lud1.home> <umoaei$16gr4$1@dont-email.me>
<20231230181414.458f441d@lud1.home> <umqca4$1eokp$1@dont-email.me>
<20231230215329.243c26f2@lud1.home> <umqidb$1fcdk$1@dont-email.me>
<20231231011828.38444f56@lud1.home> <ums6a7$1po0r$1@dont-email.me>
<20231231142543.77bb94c4@lud1.home> <20231231161455.1a2d8f4a@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 31 Dec 2023 23:26:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d49416446e44b8cbdc7ffe5e7607d23d";
logging-data="1988269"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX191U/fne+ubmItwsoqdeKnU"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:q92UtA68bDAYzfmzxBjfCsaGO2k=
Content-Language: en-US
In-Reply-To: <20231231161455.1a2d8f4a@lud1.home>
 by: et99 - Sun, 31 Dec 2023 23:25 UTC

On 12/31/2023 11:14 AM, Luc wrote:
> Greetings from the drawing board.
>
> My threaded version of the thing I'm working on is actually slower than
> the previous design.

> foreach chunk [dict keys $chunks] {
> set tid_$chunk [thread::create {thread::wait}]
> unset -nocomplain resultof_$chunk
> thread::send -async [set tid_$chunk] [populate] resultof_$chunk
> if {![info exist resultof_$chunk]} {vwait resultof_$chunk}
> }

In the above, [populate] is not done in the second thread, but is instead processed before thread::send even sees it. So, whatever populate returns, is sent into a thread and when that's done, it sets your return variable.

Looking at populate, the return value is likely the last [.t image create], which returns a unique identifier. I suspect the thread sees that and actually throws an error, since it's not a valid script to execute. I forget whether that ends up killing the thread or just goes silently into the night.

Also, each thread runs in it's own interpreter. So, that .t created in the main thread is not visible to the second thread. In fact, tk in a second thread even has its own event loop and everything else that a gui has. It's almost like being a separate process. And if you do a package require Tk in that second thread, you'll end up with another widget tree beginning at .

Re: Inserting thousands of images in a text widget - too slow

<umt0qm$1t1gk$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12689&group=comp.lang.tcl#12689

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Mon, 1 Jan 2024 00:25:58 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <umt0qm$1t1gk$1@dont-email.me>
References: <20231229142620.140d719b@lud1.home> <umoaei$16gr4$1@dont-email.me> <20231230181414.458f441d@lud1.home> <umqca4$1eokp$1@dont-email.me> <20231230215329.243c26f2@lud1.home> <umqidb$1fcdk$1@dont-email.me> <20231231011828.38444f56@lud1.home> <ums6a7$1po0r$1@dont-email.me> <20231231142543.77bb94c4@lud1.home> <umshl4$1r78o$1@dont-email.me> <20231231174858.7ae4501d@lud1.home>
Injection-Date: Mon, 1 Jan 2024 00:25:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="04b415232adde9334f8db1a9a02e0759";
logging-data="2000404"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/q6QdxRBnCKj0cm/zdY30J"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:G64aRxTCo7TBFbTAfd8uj8NX8YI=
 by: Rich - Mon, 1 Jan 2024 00:25 UTC

Luc <luc@sep.invalid> wrote:
> On Sun, 31 Dec 2023 20:07:00 -0000 (UTC), Rich wrote:
>>How did you specify the font?
>>
>
> Then I added the font specification to the line that creates the button:
>
> button $tx.b$x -font {Arial 14} -text $x -width 80 -cursor arrow -image IMAGE -compound left
>
> 76111 ms

You specified the font in a much less than optimal way.

You want to create a named font using "font create", then use that
named font for the "-font" option.

Your way probably had Tk redoing all the font rasterizing anew for each
line. Using a named Tk font you only pay the font lookup and
rasterizing once. An added advantage is that if you then "font
configure" that named font later, the updates propagate automatically
to every widget that uses the named font.

Re: Inserting thousands of images in a text widget - too slow

<20240109212347.52a6e238@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12745&group=comp.lang.tcl#12745

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.gegeweb.eu!gegeweb.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc...@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: Inserting thousands of images in a text widget - too slow
Date: Tue, 9 Jan 2024 21:23:47 -0300
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <20240109212347.52a6e238@lud1.home>
References: <20231229142620.140d719b@lud1.home>
<umoaei$16gr4$1@dont-email.me>
<20231230181414.458f441d@lud1.home>
<umqca4$1eokp$1@dont-email.me>
<20231230215329.243c26f2@lud1.home>
<umqidb$1fcdk$1@dont-email.me>
<20231231011828.38444f56@lud1.home>
<ums6a7$1po0r$1@dont-email.me>
<20231231142543.77bb94c4@lud1.home>
<umshl4$1r78o$1@dont-email.me>
<20231231174858.7ae4501d@lud1.home>
<umt0qm$1t1gk$1@dont-email.me>
<20240102113748.56565f76@lud1.home>
<un1ahr$2oa7d$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="f44a4217c776c85c1fae172514c61ccb";
logging-data="2322131"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+zstImhAREpmYkGrmcKC3UwxQ7bRjlgTQ="
Cancel-Lock: sha1:P1FvkBK55+VTQCxwIgkzir+gKQg=
 by: Luc - Wed, 10 Jan 2024 00:23 UTC

Rich et al,

In case you're interested, my bug report has received comments:

https://core.tcl-lang.org/tk/tktview/737abf45230d38c450c031d1c89ea84811d54e3e

I appreciate it very very much.

When that fix hits the streets I will be able to rewrite the largest
proc in my application in a much simpler way. But I still like to think
that the more complicated version will always be there for users of old
Tcl/Tk versions to fall back on. And I learned how to use threads.
No effort is lost in life until life itself is lost.

Thank you all.

--
Luc
>>

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor