Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2011-05-06
01:03 • Ticket [1158008fff] new list internal rep status still Closed with 4 other c... artifact: c15a9a2381 user: dgp
2006-09-30
00:31 • Closed ticket [1158008fff]. artifact: f1db90c5c3 user: msofer
2005-04-25
17:05 • Ticket [1158008fff]: 5 changes artifact: 9c26a1e5df user: dkf
14:02 • Ticket [1158008fff]: 4 changes artifact: 7dd877eef3 user: jenglish
2005-04-05
23:19 • Open ticket [1158008fff]. artifact: da9ea8e59d user: msofer
22:41 • Ticket [1158008fff]: 6 changes artifact: cf0c30ae32 user: dkf
21:36 • Ticket [1158008fff]: 6 changes artifact: 439012f13a user: dkf
2005-04-02
08:56 • Add attachment listPatch2 to ticket [1158008fff] artifact: 0580391f62 user: msofer
08:56 • Ticket [1158008fff] new list internal rep status still Pending with 8 other ... artifact: 094022867b user: msofer
08:56 • Pending ticket [1158008fff]. artifact: 053a91351e user: msofer
2005-04-01
19:13 • Ticket [1158008fff]: 4 changes artifact: a9058c9320 user: dkf
2005-03-09
02:11 • Ticket [1158008fff]: 4 changes artifact: 72f573e413 user: msofer
2005-03-07
08:05 • Ticket [1158008fff]: 4 changes artifact: 98df6de49a user: msofer
08:05 • Add attachment listPatch to ticket [1158008fff] artifact: 3a11165c8e user: msofer
01:05 • New ticket [1158008fff] new list internal rep. artifact: 726b73da1c user: msofer

new list internal rep

Closed / Accepted1158008fffffffffffffffffffffffffffffffffCreated 22 years agoUpdated 16 years ago
Descriptionplain2005-03-07 01:05:59
Attached a patch against HEAD that changes the internal
reps of objects. The changes are:

(1) The List struct is now growable and contains the
pointers to the list elements at the end. This reduces
the number of mallocs in list creation from 2 to 1.

(2) The List struct is now refcounted. This permits
insuring that the pointers to the list elements survive
a possible shimmering of the object (by increasing the
ref count). This is now use in Tcl_EvalObjEx (pure list
opt) and TclLsetList (so that it calls TclLsetFlat)

(3) All empty lists in a thread share the same List
internal rep. In this manner, an empty list can be
allocated and reserved without any malloc/free calls

The patch passes the testsuite. It has not been tested
for leaks yet. There shouldn't be any ...

CAVEAT: callers of Tcl_ListObjGetElements should *not*
change the elements, even if the Tcl_Obj is unshared
(as its internal rep may be shared). This was IMO
already an abuse of the api, but it is valid in the
unpatched implementation and invalid with the patch.
The docs are silent about this; they do not even
mention that the Tcl_Obj should not be shared for an
edit to be valid. Maybe throw some new CONST into that api?
msoferplain2005-03-07 08:05:59
File Added - 124431: listPatch
msoferplain2005-03-09 02:11:12
Logged In: YES 
user_id=148712

Joe English remarks that TSD access may be expensive, so
that the proposed sharing of empty lists may not be
worthwhile. One solution is to alloc them on demand (code
for that is #if-zeroed out in the patch), another one is to
define a struct for thread-specific data, store a pointer in
a tsd and another pointer (at creation time) in each interp
in that thread.
dkfplain2005-04-01 19:13:45
Logged In: YES 
user_id=79902

I'm not convinced yet that combining the array and the
structure is a good idea. Perhaps pooling the List instances
would be a better approach, but that's impossible with
var-length structures.

I also wonder whether sharing the List just within an Interp
would be easier?
msofer Pending ticket [1158008fff]. [History diff]2005-04-02 08:56:05
msoferplain2005-04-02 08:56:06
File Added - 128163: listPatch2

Logged In: YES 
user_id=148712

New patch attached (committed to HEAD). Changes are:

* better resolution of the "empty list" issue: an empty
Tcl_Obj is always returned in that case, calling
Tcl_ListObjGetElements on it returns length==0 and
objv==NULL. All list ops know how to detect and operate with
empty lists.

* warning in the docs about not mucking with the contents of
the array returned by Tcl_ListObjGetElements is strengthened

This dissolves the TSD issue, as there is no sharing of
empty List structs.

Leaving "Pending" and assigning to donal for clarification
of the issues with the var-length structs.
dkfplain2005-04-05 21:36:32
Logged In: YES 
user_id=79902

My #1 issue is that var length structures are a mess. They
require all sorts of nasty things to work with them, and
must be tested rigorously on lots of architectures because
of alignment issues. :^(

If we pool List instances, the likely number of allocations
per list creation is still just one and we don't have to do
address munging to make it all "just work".
dkfplain2005-04-05 22:41:12
Logged In: YES 
user_id=79902

Random thought: I wonder whether it would be possible to
allocate List instances from the same pool as Tcl_Objs?
msofer Open ticket [1158008fff]. [History diff]2005-04-05 23:19:28
jenglishplain2005-04-25 14:02:53
Logged In: YES 
user_id=68433

See also: #1189274  and #1178805.

I don't think all the special-case checks for empty lists
and all the new bugs (including the ones that haven't been
discovered yet) are worth trying to save a malloc() here and
there.  Please reconsider the empty list special case.
dkfplain2005-04-25 17:05:42
Logged In: YES 
user_id=79902

Assigning to the person who started checking in code since
it seems to have caused someone problems.
msofer Closed ticket [1158008fff]. [History diff]2006-09-30 00:31:39
dgpplain2011-05-06 01:03:34
Six years later, the question about all the empty list
special case effort arises again.  Please compare
core-8-5-branch and dgp-list-simplify and tell me
what benefits of avoiding List allocation for empty
lists I'll be sorry doing without on the dgp-list-simplify branch.
Thanks.
Log in (anonymous is fine) to add a comment.

Attachments: