Skip to content
Tcl Source Code Artifact [90c938ccf2]
Login

Artifact [90c938ccf2]

Artifact 90c938ccf23984a65975780944dcb0f04f9ba1d6e75788be8bcc3428d6f480d8:

Ticket change [90c938ccf2] - New ticket [02d5d65d70adab97|02d5d65d70] <i>File subsystem commands and operations suffer from unneeded (but expensive) path normalization</i>. by sebres on 2024-09-13 11:35:11.
D 2024-09-13T11:35:11.660
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-wiki
J comment It\slooks\slike\smore\sthan\s20\syears\s(for\sinstance\ssince\s2003\sin\s[da7df285d16e6c30]),\stcl's\sfile\srelated\sfunctions\sand\scommands\ssuffer\sfrom\sunneeded\spath\snormalization\sand\stherefore\sunnecessarily\sslower\sthan\sthey\smay\sbe.\r\n\r\nThis\sis\salmost\sinvisible\sif\sone\sis\stesting\swith\sconstant\spath\s(literals),\sbecause\sthey\shold\sthen\snormalized\spath\sin\sinternal\srepresentation,\sbut\svery\swell\sbothering\son\svariable\spath\sobjects,\swhat\sis\smostly\sthe\snormal\scase,\sif\spaths\sgets\sgenerated,\sread\sfrom\ssomewhere,\sanyway\sdynamically\sconstructed\severy\stime\sbefore\stheir\susage.<br/>\r\nBut\sthe\spath\snormalization\sis\svery\sexpensive,\sespecially\sit\sis\snoticeable\son\shosts\swith\srude\scorporate\s"protection"\ssoftware\slike\sAV/DLP/Endpoint-Protection/Whatever-else-bothers-dev-to-work.\r\n\r\nJust\snote\sthat\sparticularly\sby\swindows\sthe\sfunction\s<i>TclpObjNormalizePath</i>\sdoing\s<i>GetFileAttributesExW</i>\s+\s<i>WinReadLinkDirectory</i>\s+\s<i>FindFirstFileW</i>\s(basically\sglob)!\r\n\r\nBelow\sare\s2\sexamples\sillustrating\sthis\sbehaviour\son\ssuch\sa\shost.\sNote\sthat\s_determ_fn\salways\screates\snew\sobject,\sand\s<i>string\strim</i>\sis\sused\sonly\sto\sforce\sthis,\sas\swell\sas\sthe\scosts\sof\ssuch\spath\sgeneration\sis\salmost\sto\sneglect\s(0.01%),\sadditionally\sthe\sT:-drive\sused\shere\sis\sa\sRAM-disk:\r\n<code><pre>\r\n\s\s%\sproc\s_determ_fn\s{i}\s{\sstring\strimright\s"T:/TestCLU/a7/40vbp43/vu/3g/616q4bet2lf53lf88vo5q2.ent\s"\s}\r\n\s\s%\stimerate\s{\sset\sfn\s[_determ_fn\s123]\s};\s#\scosts\sof\sdeterministic\spath\sgeneration\r\n\s\s<b>0.457163\sµs/#\s2081613\s#\s2187404\s#/sec\s951.636\snet-ms</b>\r\n\s\s%\sset\sfn\s[_determ_fn\s123];\stimerate\s{\sclose\s[open\s$fn]\s};\s#\s1\stime\snormalization\r\n\s\s<b\sstyle="color:green;">1411.53\sµs/#\s709\s#\s708.45\s#/sec\s1000.774\snet-ms</b>\r\n\s\s%\stimerate\s{\sset\sfn\s[_determ_fn\s123];\sclose\s[open\s$fn]\s};\s#\severy\stime\snormalization\r\n\s\s<b\sstyle="color:red;">3060.91\sµs/#\s327\s#\s326.70\s#/sec\s1000.917\snet-ms</b>\r\n</pre></code>\r\n\r\nThe\scost\sof\ssuch\s(unneeded\shere!)\snormalization\soverhead\s-\s1650\sµs,\sso\s<b>more\sthan\s50%.</b>\r\nThe\ssame\sis\svalid\sfor\sanother,\smuch\sfaster\sfile\scommands\slike\s<i>file\sexists</i>,\s<i>file\sattributes</i>,\s<i>file\sstat</i>\setc.\sHowever\sthere\sthe\soverhead\smay\sbe\s<b>up\sto\s95%</b>\sunder\snormal\scircumstances\sor\s<b>up\sto\s1000%</b>\son\shosts\swith\srude\scorporate\sinfrastructure\sor\sfor\sUNC-paths\sover\snetwork\s(samba,\scifs,\snfs,\setc):\r\n<code><pre>\r\n\s\s%\sset\sfn\s[_determ_fn\s123];\stimerate\s{\sfile\sexists\s$fn\s};\s#\s1\stime\snormalization\r\n\s\s<b\sstyle="color:green;">4.277398\sµs/#\s116259\s#\s233786\s#/sec\s497.286\snet-ms</b>\r\n\s\s%\stimerate\s{\sset\sfn\s[_determ_fn\s123];\sfile\sexists\s$fn\s};\s#\severy\stime\snormalization\r\n\s\s<b\sstyle="color:red;">1505.03\sµs/#\s665\s#\s664.44\s#/sec\s1000.845\snet-ms</b>\r\n</pre></code>\r\n\r\n<b>I\swould\slike\sto\semphasise\sonce\sagain</b>\s-\sthe\sconstant\sliteral\spaths\sis\srather\san\sexception,\sbecause\sthe\snormal\scase\sis\susually\sa\sdynamic\spath\sobject\sthat\sis\screated\sor\sread\sfrom\ssomewhere\sinstantly\sbefore\sits\susage:\scorresponds\sthe\ssecond\s(red)\scase\sin\sboth\sillustrations\sabove.\r\n\r\nI\salready\sfixed\sthis\sand\swill\stry\sto\sprovide\sa\ssolution\ssoon\stogether\swith\sperformance\sregression-test\scoverage.
J foundin any
J is_private 0
J login sebres
J priority 5\sMedium
J private_contact 50e9528765c18296566374b3fde2df942c394efd
J resolution None
J severity Minor
J status Open
J submitter sebres
J subsystem -\sNew\sBuiltin\sCommands
J title File\ssubsystem\scommands\sand\soperations\ssuffer\sfrom\sunneeded\s(but\sexpensive)\spath\snormalization
J type Bug
K 02d5d65d70adab975fce0c87800140999ab80f3e
U sebres
Z 2b64a6110903e0d6e10fb4e0f55f0434