My application can load that huge directory almost instantaneously if I >disable the icons. It's clear the icons slow everything down. Badly.one way is to load just as many icons as are visible at one moment
But they are important aesthetically.
Is there some way around this problem? Can I make it faster?
Much, much faster?
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?
You didn't need all that complicated code here.
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.
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.
If you are going to allow for user custom icon sets then that means
some trickery to work around the issue.
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.
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.
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 📄
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.
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...
Ok, so a way around the "slow images" is to use buttons containing
images.
Why, it seems you've found an excellent workaround.
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!
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?
Luc <[email protected]d> 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?
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".
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}
}
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.
On Mon, 1 Jan 2024 00:25:58 -0000 (UTC), Rich wrote:
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.
No, I tried using font create and it's very slow too. Exactly as slow
as the version with the -font specification places where you told me
was wrong.
button $tx.b$x -font {Arial 14} -text $x
----------------------------
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 -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}
font create myfont -family Freesans -size 14
set begin [clock milliseconds]
image create photo IMAGE -file /usr/share/icons/hicolor/32x32/apps/elk.png for {set x 1} {$x <= 2000} {incr x} {
button $tx.b$x -font myfont -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"
focus $tx
$tx see end
--------------------------
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 00:01:46 |
| Calls: | 12,097 |
| Calls today: | 5 |
| Files: | 15,003 |
| Messages: | 6,517,857 |