Artifacts Associated With Ticket f5c01e42a759e6a0
Ticket change [537805bb98] (rid 217054) by apnadkarni on 2023-08-08 05:52:06:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-markdown"
- comment initialized to:
Reported by Paul O. on the core mailing list: Can anybody confirm the slow behaviour of the "array get" command in Tcl 9? Noticed on both Windows and Linux. Regards, Paul ``` puts "Using Tcl [info patchlevel] on $tcl_platform(platform)" catch { puts "Build-Info: [tcl::build-info]" } set startTime [clock milliseconds] for { set i 1 } { $i < 6000 } { incr i } { set arr(Key-$i) "Value-$i" } puts "Build time: [expr { [clock milliseconds] - $startTime }] msec" set startTime [clock milliseconds] set tmp [list] foreach {key val} [array get arr "*"] { lappend tmp $val } puts "Get time : [expr { [clock milliseconds] - $startTime }] msec" exit 0 ``` - foundin initialized to: "9.0"
- is_private initialized to: "0"
- login: "apnadkarni"
- priority initialized to: "5 Medium"
- private_contact initialized to: "9546e9877f1a8899e25a89082561ee694e7fb402"
- resolution initialized to: "None"
- severity initialized to: "Severe"
- status initialized to: "Open"
- submitter initialized to: "apnadkarni"
- subsystem initialized to: "- New Builtin Commands"
- title initialized to:
Performance regression in 9.0 accessing dicts as lists
- type initialized to: "Bug"
Ticket change [fd7a61a0f0] (rid 217055) by apnadkarni on 2023-08-08 05:53:23:
- icomment:
Confirmed the slowdown occurs even with an empty loop and with any dictionary (not just that returned by array get).
- login: "apnadkarni"
- mimetype: "text/plain"
- icomment:
Ticket change [89b5bcc916] (rid 217059) by apnadkarni on 2023-08-08 06:08:38:
- assignee changed to: "griffin"
- icomment:
Temporarily fixed in [bd17e3ed36] by NULL-ing DictAsListIndex from the Dict type dispatch table. My opinion is that once list operations are used on a dictionary, it is reasonable and in fact appropriate to shimmer it. That's the general philosophy across all of Tcl's shimmering operation. It is the script responsibility to use the appropriate commands. But may be it is possible to have the best of both worlds in this case if some use can be made of dict's list-like internal capabilities. Leaving open and assigning to Brian for his opinion.
- login: "apnadkarni"
- mimetype: "text/x-fossil-plain"
Ticket change [3779b1de5c] (rid 217074) by pspjuth on 2023-08-08 20:04:12:
- icomment:
A main problem with the Index and Length functions are that they generate the string representation, which is *much* more expensive than shimmering. I agree with Ashok's assessment that shimmering is the sensible option for those operations. Especially since dict-list shimmering is well optimised.
- login: "pspjuth"
- mimetype: "text/plain"
- icomment:
Ticket change [70cbb15089] (rid 217093) by pointsman on 2023-08-10 09:48:16:
- icomment:
Disabling DictAsListIndex as done by Ashok with [bd17e3ed36] even fixed a panic, seen by me. See [b6257b82833b] for the details.
- login: "pointsman"
- mimetype: "text/x-fossil-plain"
- icomment:
Ticket change [fe37f6c6e7] (rid 217233) by griffin on 2023-08-16 22:30:19:
- icomment:
With some details added to the testcase: ``` puts "Using Tcl [info patchlevel] on $tcl_platform(platform)" catch { puts "Build-Info: [tcl::build-info]" } set startTime [clock milliseconds] for { set i 1 } { $i < 60000 } { incr i } { set arr(Key-$i) "Value-$i" } set bt [expr { [clock milliseconds] - $startTime }] puts "Build time: $bt msec" set startTime [clock milliseconds] set agx [array get arr "*"] set at [expr { [clock milliseconds] - $startTime }] puts "array get time : $at msec" puts agx-is-a:[lrange [tcl::unsupported::representation $agx] 1 3] set startTime [clock milliseconds] set llen [llength $agx] set lt [expr { [clock milliseconds] - $startTime }] puts "llength time: $lt msec" puts llen=$llen set startTime [clock milliseconds] set tmp [list] foreach {key val} $agx { lappend tmp $val } set gt [expr { [clock milliseconds] - $startTime }] puts "Get time : $gt msec" exit 0 ``` Part 1 fix improves llength operation: ```` # main code # Using Tcl 9.0a4 on unix Build-Info: 9.0a4+35275c285b06f3932d83aadec6dd9df85dd34214ca0202316409e117b8abe496.compiledebug.debug.gcc-1104.memdebug.no-optimize Build time: 1287 msec array get time : 160 msec agx-is-a:is a dict llength time: 80 msec llen=119998 Get time : 916 msec # with dict llength function (branch [bug-f5c01e42a7]) # Using Tcl 9.0a4 on unix Build-Info: 9.0a4+840ebea1b54a1edbefb5f74244bee34c43afef69111ac4f12f0b4a165003bd1a.compiledebug.debug.gcc-1104.memdebug.no-optimize Build time: 1035 msec array get time : 142 msec agx-is-a:is a dict llength time: 0 msec llen=119998 Get time : 499 msec ```` More to come... - login: "griffin"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [84df64e2e9] (rid 217239) by griffin on 2023-08-17 21:13:47:
- closedate changed to: "2460174.38457823"
- closer changed to: "griffin"
- icomment:
Shimmering is the best performance possible w/o major rewrite of dict. The llength operation has been optimized by computing and caching the llength when the dict is created and modified. Having llength value available helps a bit in general. Fixed:[2a01c62b1a]
- login: "griffin"
- mimetype: "text/x-markdown"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [ef2fa00bca] (rid 217268) by apnadkarni on 2023-08-20 13:36:31:
- closer changed to: "nobody"
- icomment:
Brian, Re-opening as the commit triggered failures in tcllib tests. Have reverted the commit on trunk for the time being so tcllib testing can proceed. You can revert the reversion (and a fix) if you think the optimization is worthwhile but my opinion is that use of a llength operation on a dictionary is more likely than not followed by other list operations in the cases that are not programming errors so the shimmering will happen anyways. So it not clear to me that the specialization is worth the effort.
- login: "apnadkarni"
- mimetype: "text/plain"
- resolution changed to: "None"
- status changed to: "Open"
Ticket change [fa39a29458] (rid 217272) by griffin on 2023-08-21 00:32:10:
- icomment:
Thanks Ashok! I agree, the benefit is limited, so the overall advantage is questionable. Reviewing the changes, I think I see the problem. When I have some free time I will attempt a fix, just to satisfy my curiosity, but may not commit. The lack of performance benchmarks makes this kind of thing tricking to analyze and validate.
- login: "griffin"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [912ee31b93] (rid 218208) by griffin on 2023-09-15 01:03:48:
- closedate changed to: "2460202.54430663"
- closer changed to: "griffin"
- icomment:
Closing this ticket. Current trunk is optimal. Will not "fix", i.e., implementing abstract list for dict beyond llength is not worthwhile.
- login: "griffin"
- mimetype: "text/x-markdown"
- resolution changed to: "Fixed"
- status changed to: "Closed"