Skip to content
Tcl Source Code Artifact [11c586bf64]
Login

Artifact [11c586bf64]

Artifact 11c586bf64b3fe2e658c8c534b7383210d7999cf972b9c6d0777112fe8a599b5:

Ticket change [11c586bf64] - New ticket [3d1c409f1afbca6b|3d1c409f1a] <i>Bad performance: tclThreadAlloc vs. CPU-cache (fragmentation/granularity/etc)...</i>. by sebres on 2024-11-18 14:11:40.
D 2024-11-18T14:11:40.610
J assignee nobody
J closer nobody
J cmimetype text/x-markdown
J comment (Just\sfor\sthe\srecord,\sinitially\sposted\sin\schat\sin\s2019\s-\s[paste.tclers.tk/5260](http://paste.tclers.tk/5260)).\r\n\r\nIssue:\sthe\slonger\sTcl\sworks\s-\sthe\sslower\sit\sbecomes...\r\n\s\r\nThe\ssimplest\sexample\sillustrating\sthis:\r\n\r\n```\s\r\n\s\sproc\stest\s{}\s{timerate\s-calibrate\s{incr\si}\s10000\s10000000};\stest;\s#\scalibrate\soverhead\sfor\sincr\r\n\s\sproc\stest\sargs\s{\r\n\s\s\s\sputs\s"set:\s[timerate\s{\sset\sa([incr\si])\s_\s}\s{*}$args]";\s\r\n\s\s\s\slset\sargs\s1\s$i;\sset\si\s0;\s\r\n\s\s\s\sputs\s"get:\s[timerate\s{\sset\sa([incr\si])\s}\s{*}$args]"\r\n\s\s}\r\n\s\stime\s{\stest\s10000\s1000000\s}\s50\r\n```\r\n\r\nResults:\r\n\r\n```\r\n*\s1x-threaded:\r\n\s\s\s\sset:\s0.153809\sµs/#\s1000000\s#\s6501570\s#/sec\s153.809\snet-ms\r\n\s\s\s\sget:\s0.049532\sµs/#\s1000000\s#\s20188968\s#/sec\s49.532\snet-ms\r\n\s\s\s\s...\s100\stimes\s...\r\n\s\s\s\sset:\s0.598031\sµs/#\s1000000\s#\s1672154\s#/sec\s598.031\snet-ms\r\n\s\s\s\sget:\s0.331693\sµs/#\s1000000\s#\s3014836\s#/sec\s331.693\snet-ms\r\n*\s16x-threaded:\r\n\s\s\s\sset\s*\s16x:\s0.573478\sµs/#\s4000000\s#\s291248\s#/sec\s2293.913\snet-ms\r\n\s\s\s\sget\s*\s16x:\s0.077514\sµs/#\s4000000\s#\s14923264\s#/sec\s310.059\snet-ms\r\n\s\s\s\s...\s20\stimes\s...\r\n\s\s\s\sset\s*\s16x:\s3.539208\sµs/#\s4000000\s#\s304646\s#/sec\s14156.834\snet-ms\r\n\s\s\s\sget\s*\s16x:\s0.519618\sµs/#\s4000000\s#\s2048606\s#/sec\s2078.474\snet-ms\r\n```\r\n\r\nFirst\sproblem\s-\sreleasing\sof\sobjects\s(and\sits\sfollowed\sholding\sin\slinked\sLIFO\sof\sobject\spool)\smay\shappen\srandomly,\sso\sthe\sobjects\sare\sdistributed\sacross\sdifferent\smemory\sblocks\s(by\sthe\sway,\snot\sconsidering\scache\scoherency),\sand\son\sfurther\sallocs\sbecomes\s"fragmented"\sacross\sdifferent\scache\sblocks,\swhat'd\scause\smany\sCPU-cache\swashouts\sand\srelated\sreloads.\r\nLong\sfragmentation\sof\ssuch\skind\sin\sthe\sin\sobject\spool\sLIFO\swill\sonly\sexacerbate\sthe\sproblem.\r\n\r\nThe\ssecond\sproblem\sis\sthat\sbesides\sfragmentation/granularity,\sthe\ssingle\smem-block\sthat\sgets\s"changed"\sin\ssome\sthread,\swill\scause\sthat\sthe\swhole\sblock\sin\scache\sneeds\sto\sbe\sinvalidated\sfor\sother\sthreads,\swhat\sin\sturn\swould\scause\smore\smemory\saccesses\s(which\sis\shundred\stimes\sslower\sthan\sL2\sand\sthousand\stimes\sslower\sthan\sL1\saccess).\r\n\r\nIn\smy\sfork\sI\sfixed\sthis\s"wrong"\sbehaviour\sin\smy\sown\sthreaded-alloc\smodule,\swhich\sprefers\smoving\sof\swhole\sfree\spages\sthe\ssingle\sobjects,\sand\scombining\sthem\sto\ssingle\sfree\sblock\sinstead\sof\ssimplest\sLIFO\sin\sthreaded\sobject\spool:\r\n\r\n```\r\n*\s1x-threaded:\r\n\s\s\s\sset\s:\s0.140644\sµs/#\s250000\s#\s7110150\s#/sec\s35.161\snet-ms\r\n\s\s\s\sget\s:\s0.018572\sµs/#\s250000\s#\s53844497\s#/sec\s4.643\snet-ms\r\n\s\s\s\s...\s100\stimes\s...\r\n\s\s\s\sset\s:\s0.083600\sµs/#\s250000\s#\s11961722\s#/sec\s20.900\snet-ms\r\n\s\s\s\sget\s:\s0.017704\sµs/#\s250000\s#\s56484410\s#/sec\s4.426\snet-ms\r\n*\s16x-threaded:\r\n\s\s\s\sset\s*\s16x:\s0.810806\sµs/#\s4000000\s#\s129652\s#/sec\s3243.227\snet-ms\r\n\s\s\s\sget\s*\s16x:\s0.556715\sµs/#\s4000000\s#\s246766\s#/sec\s2226.860\snet-ms\r\n\s\s\s\s...\s20\stimes\s...\r\n\s\s\s\sset\s*\s16x:\s0.665778\sµs/#\s4000000\s#\s1671624\s#/sec\s2663.113\snet-ms\r\n\s\s\s\sget\s*\s16x:\s0.343585\sµs/#\s4000000\s#\s3428775\s#/sec\s1374.340\snet-ms\r\n```
J foundin any
J is_private 0
J login sebres
J priority 5\sMedium
J private_contact 50e9528765c18296566374b3fde2df942c394efd
J resolution None
J severity Severe
J status Open
J submitter sebres
J subsystem 41.\sMemory\sAllocation
J title Bad\sperformance:\stclThreadAlloc\svs.\sCPU-cache\s(fragmentation/granularity/etc)...
J type Bug
K 3d1c409f1afbca6b74f824cffe8dbb4028a410c5
U sebres
Z 19e27d7a56aa89902b0d0e3805e39333