Overview
| Artifact ID: | a064c6601d4c17d23610f49b5d48b7c56918995e8ec8d8bb04ffef342f5eb7c7 |
|---|---|
| Ticket: | 7da6c2d04c219e8ed4896b9d4e9eb88e586447f2
fileevent poor performance due to shimmering |
| User & Date: | ralfixx on 2026-05-26 17:54:55 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-markdown"
- comment changed to:
When a fileevent is set up to include the data read from the channel, the performance is dramatically reduced due to shimmering from list to string in Tcl_FileEventObjCmd(). Script: set up a pipeline, and on each read in the fileevent, reset the fileevent script to include the new data. I have intentionally limited the read to 65536 bytes at one time in order to show the problem. <pre> proc read_channel {fd data} { append data [read $fd 65536] # puts stderr "[string length $data]" if {[eof $fd]} { set now [clock milliseconds] puts stderr "read [string length $data] bytes in [expr {$now-$::start}]ms" catch {close $fd} set ::forever 1 return } fileevent $fd readable [list read_channel $fd $data] } set fd [open "|dd if=/dev/zero bs=65536 count=200" rb] fconfigure $fd -blocking 0 set start [clock milliseconds] fileevent $fd readable [list read_channel $fd ""] vwait forever </pre> Tcl_FileEventObjCmd() is checking whether to remove the fileevent by issuing a TclGetString() on the fileevent script and checking whether the returned string is '\\0' <pre> generic/tclIO.c #9285 /* * If we are supposed to delete a stored script, do so. */ if (*(TclGetString(objv[3])) == '\0') { DeleteScriptRecord(interp, chanPtr, mask); return TCL_OK; } </pre> This causes the fileevent script to shimmer into a string each time the filevent is reset. Proposed patch: I think it is safe to assume that fileevent scripts should be valid lists, so we could check the list length instead. If I do so, the perfomance is greatly enhanced (20x). Original tcl9.0.3 <code> read 13107200 bytes in 10245ms </code> With proposed patch applied: <code> read 13107200 bytes in 529ms </code> - foundin changed to: "9.0.3"
- is_private changed to: "0"
- login: "ralfixx"
- priority changed to: "5 Medium"
- private_contact changed to: "1d3c95db24e116878d6afed7cf890a89a0effe62"
- resolution changed to: "None"
- severity changed to: "Important"
- status changed to: "Open"
- submitter changed to: "ralfixx"
- subsystem changed to: "24. Channel Commands"
- title changed to: "fileevent poor performance due to shimmering"
- type changed to: "RFE"