Ticket UUID: | 1701202 | |||
Title: | Tcl stack reform | |||
Type: | Patch | Version: | TIP Implementation | |
Submitter: | msofer | Created on: | 2007-04-16 00:30:38 | |
Subsystem: | 41. Memory Allocation | Assigned To: | msofer | |
Priority: | 5 Medium | Severity: | ||
Status: | Closed | Last Modified: | 2007-06-06 01:36:45 | |
Resolution: | Accepted | Closed By: | msofer | |
Closed on: | 2007-06-05 18:36:45 | |||
Description: |
Since we started using TclStackAlloc, some of the basic assumptions underlying tebc's mem design ceased being correct. In particular, when the stack is grown the old stack will now typically remain active until every bytecode running in it returns - as the corresponding CallFrames live there, the old stacks remain active. This means that the recopying of stack items is not really necessary. This patch redesigns the ExecEnv system to work differently: there may be many stacks (in a doubly-linked list). When there is not enough room left in the active stack, the next one is used if it exists (it will be both the last one and empty) - but no elements are typically copied over (exception: growth for {*}-expansion). On freeing of a stack requirement, empty stacks that are not last are ckfree'd. In this manner the largest stack allocated remains always here, smaller stacks are ckfreed when they cease being used. This behaviour is similar to what de facto we have now, with the old copies being blocked by TclStackAlloc'ed frames. With this patch both performance and memory usage should improve in general, although it is possible to devise cases where it consumes more memory than the current scheme. Performance improvements (small, seem to be about 5% on my very unreliable benchmariking setup) due to: (a) CACHE_STACK_INFO now necessary, a running bc can not get its stack changed (except by it using {*}, so the adaptation is localised there) (b) when a new stack is needed for a new bytecode, no data is copied over. When {*} requires a new stack, only the data corresponding to the current bc is copied over. The current scheme requires a copy of the complete stack contents, including every TclStackAlloc'ed sections. (c) (epsilon squared) there is no more refcounting of the stacks Memory improvements: when a new stack is allocated, the complete memory is available as nothing is copied over from older stacks. The *2 growth might be too generous under these circumstances, maybe 1.5 would be enough? The patch also creates a new TclStackRealloc, that permits resizing of the last TclStackAlloc'ed memory (unused, just very easy to add as it uses functionality needed for {*}). | |||
User Comments: |
msofer added on 2007-06-06 01:36:45:
File Added - 231859: 1701202.patch Logged In: YES user_id=148712 Originator: YES Removed commented-out flotsam from patch; committed File Added: 1701202.patch dgp added on 2007-05-24 01:21:57: File Added - 230285: 1701202.patch Logged In: YES user_id=80530 Originator: NO patch updated to current Tcl HEAD File Added: 1701202.patch msofer added on 2007-04-18 22:42:02: File Deleted - 225397: File Added - 225536: execEnv.patch Logged In: YES user_id=148712 Originator: YES File Added: execEnv.patch msofer added on 2007-04-18 05:39:31: File Deleted - 225089: File Added - 225397: execEnv.patch Logged In: YES user_id=148712 Originator: YES 1702212 resolved, new patch File Added: execEnv.patch dgp added on 2007-04-17 22:52:23: Logged In: YES user_id=80530 Originator: NO suspending review until 1702212 is resolved msofer added on 2007-04-16 17:54:30: Logged In: YES user_id=148712 Originator: YES Typo, missing a "not": CACHE_STACK_INFO is now NOT necessary msofer added on 2007-04-16 07:30:39: File Added - 225089: execEnv.patch |