Skip to content
Tcl Source Code History Of Ticket 54329e39c757ee2a
Login

History Of Ticket 54329e39c757ee2a

Artifacts Associated With Ticket 54329e39c757ee2a

  1. Ticket change [a9efa64d2c] (rid 216362) by apnadkarni on 2023-07-11 10:55:35:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-markdown"
    4. comment initialized to:
      This is a memory usage issue, not bug. As shown below, a foreach loop over a lseq within a proc results in a loss of the memory efficiency benefit of lseq.
      
      ```
      % set l [lseq 1000000]; llength $l
      1000000
      % proc getmem {} {set fd [open /proc/[pid]/statm]; return [read $fd][close $fd]}
      % getmem
      6026 1777 1468 558 0 412 0
      
      % foreach x $l {}
      % getmem
      6026 1777 1468 558 0 412 0
      
      % proc p l {foreach x $l {}}
      % p $l
      % getmem
      17731 13556 1477 558 0 12117 0
      ```
      
      Notice the jump in memory usage after the loop in the proc. The same loop on the command line does not increase memory.
      
      I suspect the cause is the use of Tcl_ListObjGetElements somewhere in the execution engine in lieu of Tcl_ListObjIndex.
      
    5. foundin initialized to: "9.0"
    6. is_private initialized to: "0"
    7. login: "apnadkarni"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "9546e9877f1a8899e25a89082561ee694e7fb402"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "apnadkarni"
    14. subsystem initialized to: "- New Builtin Commands"
    15. title initialized to:
      Compiled foreach uses excessive memory for lseq sequences
      
    16. type initialized to: "Bug"
  2. Ticket change [962f83d9d4] (rid 216366) by apnadkarni on 2023-07-11 11:36:54:

    1. icomment:
      Proposed fix in branch bug-54329e39c7. Needs review.
      
    2. login: "apnadkarni"
    3. mimetype: "text/x-fossil-plain"
  3. Ticket change [b67cadd69b] (rid 216367) by jan.nijtmans on 2023-07-11 12:14:16:

    1. icomment:
      Just one remark: I guess Tcl 8.7 has the same problem. So I recommend backporting this (which can be done after merging this to trunk)
      
      +1
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  4. Ticket change [5e5a2c7c27] (rid 216375) by griffin on 2023-07-11 15:34:44:

    1. icomment:
      The proposed fix looks good.  
      I wonder if it is worthwhile to have separate loops for Lists vs Abstract Lists, as GetElements is more efficient for Lists. It may be that the difference is not worth the complexity. IDK.
      
      Note that there are a number of places where DECACHE/CACHE calls need to be inserted in TBCE. I've done that in tip-636 (main). [tclExecute.c](https://core.tcl-lang.org/tcl/fdiff?v1=b7ee7c30a6f02625&v2=5d734646930c5089)
      
    2. login: "griffin"
    3. mimetype: "text/x-markdown"
  5. Ticket change [75b6e3a304] (rid 216377) by apnadkarni on 2023-07-11 16:17:15:

    1. icomment:
      I already had inserted the CACHE macros and was coding the change to distinguish between abstract and non-abstract probably as you were updating the ticket :-)
      
      The original is more efficient for non-abstract lists though I am a bit surprised at the difference. Code-wise there is very little difference calling Tcl_ListObjIndex noting that the GetElements in that fragment is done on *every* iteration. But its measurable, may be some cache effects? Who knows.
      
      Still doing performance measurements.
      
      /Ashok
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
  6. Ticket change [07b194893b] (rid 216378) by apnadkarni on 2023-07-11 16:41:07:

    1. icomment:
      Was in the process of doing that distinction. There is a some measurable difference for "traditional" lists between the getelements and index. A little surprising to me because the getelements there happens on every iteration just like the index. On the other hand, the former is a macro and the latter a function so that might be something I look at later.
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
  7. Ticket change [b9cd02b2b4] (rid 216406) by apnadkarni on 2023-07-12 06:44:56:

    1. closedate changed to: "2460137.78121505"
    2. closer changed to: "apnadkarni"
    3. icomment:
      Fixed for [9.0](https://core.tcl-lang.org/tcl/info/3435cde0f55776b4) and [8.7](https://core.tcl-lang.org/tcl/info/95cab70fe8b80e1c).
      
    4. login: "apnadkarni"
    5. mimetype: "text/x-markdown"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
  8. Ticket change [bb35b27107] (rid 216408) by jan.nijtmans on 2023-07-12 07:40:09:

    1. assignee changed to: "apnadkarni"
    2. closedate changed to: "2460137.81955027"
    3. closer changed to: "jan.nijtmans"
    4. icomment: "Many thanks, Ashok!"
    5. login: "jan.nijtmans"
    6. mimetype: "text/x-fossil-wiki"