Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: a9efa64d2c838a6d7db4dd2aa7ddda789da2ce982d7ff000d33dd20748f16e4d
Ticket: 54329e39c757ee2aac298a142ecfe2a7ebe72391
Compiled foreach uses excessive memory for lseq sequences
User & Date: apnadkarni on 2023-07-11 10:55:35
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-markdown"
  4. comment changed 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 changed to: "9.0"
  6. is_private changed to: "0"
  7. login: "apnadkarni"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "9546e9877f1a8899e25a89082561ee694e7fb402"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "apnadkarni"
  14. subsystem changed to: "- New Builtin Commands"
  15. title changed to:
    Compiled foreach uses excessive memory for lseq sequences
    
  16. type changed to: "Bug"