adam olsen kjbnfagmailcom tue mar 25 2008 1235 pm alexander belopolsky wrote python 30 set dict literals produce different bytecode dislambda123 1 0 load_const 0 1 3 load_const 1 2 6 load_const 2 3 9 build_set 3 12 return_value dislambda112233 1 0 build_map 3 3 load_const 0 1 6 load_const 0 1 9 store_map 10 load_const 1 2 13 load_const 1 2 16 store_map 17 load_const 2 3 20 load_const 2 3 23 store_map 24 return_value recently proposed patch would make dict bytecode similar set see httpbugspythonorgissue2197 later realized similar idea proposed httpbugspythonorgissue402227 rejected slowed pybench dict creation benchmark however tests linux mac os x patch gives slight improvement 12 benchmark two issues raised respect proposal 1 patch changes semantics executing stores inputs generated 2 pending item pairs get builtup evergrowing stack instead consumed pairwise promised think issues thoughts 1 case think change semantics would noticeable keys custom comparisonhash methods sideeffects doubt issue real life dont think python makes guarantees respect however desirable order specified note talking order insertions preserved whether keys created insertions first insertion hard justify difference set dict literals semantics 2 understand correctly code works frame stack grow code execution required stack size precomputed calculation necessary array allocated execution growing stack slow things respect memory usage note frame stack allocation transient bytecode loaded permanently applications bytecode size reduction may important terms peak memory usage stack size increase frames worry might generated code using disgustingly large literals batch creation still work optimizations would like try issue resolved optimizations strictly speaking dependent acceptance patch unification dict set literals would make coding easier understand idea making set literal produce frozenset accepted implemented natural fold constant set literals peephole optimizer similar optimization immediately available mutable dictionaries following approach conceivable dicts constant keys push frozen set keys constant stack preceded values order stored hash table indicate situation 1 argument build_map size dictionary inferred size frozenset top stack long hash table implementation compatible dicts sets dictionary creation simple copy operation hard work done compilation guidos support frozenset later withdrawn httpmailpythonorgpipermailpython30002008january011868html certain contexts 1 2 3 reuse literal regardless whether set frozenset dont know anybody begun implementing though playing around bit ive found _x 1 2 3 x set_x assuming _x precomputed faster larger literals break even point 10 perhaps could investigate well adam olsen aka rhamphoryncus _______________________________________________ python3000 mailing list smsbmo9552pythonorg httpmailpythonorgmailmanlistinfopython3000 unsubscribe httpmailpythonorgmailmanoptionspython3000python300040tangomucom wed 06 aug 2008 173325 0600 python3000 dict literal bytecode