<div dir="ltr">On Tue, Sep 2, 2008 at 11:18 PM,  <span dir="ltr">&lt;<a href="mailto:d-bugmail@puremagic.com">d-bugmail@puremagic.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<a href="http://d.puremagic.com/issues/show_bug.cgi?id=2331" target="_blank">http://d.puremagic.com/issues/show_bug.cgi?id=2331</a><br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Summary: Enum hashes many times slower than normal hashes<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Product: D<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Version: unspecified<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Platform: PC<br>
 &nbsp; &nbsp; &nbsp; &nbsp;OS/Version: Linux<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Status: NEW<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Severity: normal<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Priority: P2<br>
 &nbsp; &nbsp; &nbsp; &nbsp; Component: DMD<br>
 &nbsp; &nbsp; &nbsp; &nbsp;AssignedTo: <a href="mailto:bugzilla@digitalmars.com">bugzilla@digitalmars.com</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp;ReportedBy: <a href="mailto:andrei@metalanguage.com">andrei@metalanguage.com</a><br>
<br>
<br>
This is quite incredible. Consider this map of stopwords for the English<br>
language:<br>
<br>
bool[string] stopWords;<br>
<br>
static this() {<br>
 &nbsp; &nbsp;stopWords = [<br>
 &nbsp; &nbsp;&quot;a&quot;[]:1, &quot;b&quot;:1, &quot;c&quot;:1, &quot;d&quot;:1, &quot;e&quot;:1, &quot;f&quot;:1, &quot;g&quot;:1, &quot;h&quot;:1, &quot;i&quot;:1, &quot;j&quot;:1,<br>
&quot;k&quot;:1, &quot;l&quot;:1, &quot;m&quot;:1, &quot;n&quot;:1, &quot;o&quot;:1, &quot;p&quot;:1, &quot;q&quot;:1, &quot;r&quot;:1, &quot;s&quot;:1, &quot;t&quot;:1, &quot;u&quot;:1,<br>
&quot;v&quot;:1, &quot;w&quot;:1, &quot;x&quot;:1, &quot;y&quot;:1, &quot;z&quot;:1,<br>
 &nbsp; &nbsp;&quot;the&quot;:1, &quot;a&quot;:1,<br>
 &nbsp; &nbsp;&quot;about&quot;:1, &quot;above&quot;:1, &quot;across&quot;:1, &quot;afterwards&quot;:1, &quot;after&quot;:1, &quot;again&quot;:1,<br>
&quot;against&quot;:1, &quot;ago&quot;:1, &quot;almost&quot;:1, &quot;along&quot;:1,<br>
 &nbsp; &nbsp;&quot;already&quot;:1, &quot;always&quot;:1, &quot;among&quot;:1, &quot;anywhere&quot;:1, &quot;around&quot;:1, &quot;as&quot;:1,<br>
&quot;at&quot;:1, &quot;away&quot;:1,<br>
 &nbsp; &nbsp;&quot;back&quot;:1, &quot;before&quot;:1, &quot;behind&quot;:1, &quot;beside&quot;:1, &quot;between&quot;:1, &quot;beyond&quot;:1,<br>
&quot;by&quot;:1,<br>
 &nbsp; &nbsp;&quot;down&quot;:1, &quot;downstairs&quot;:1, &quot;during&quot;:1,<br>
 &nbsp; &nbsp;&quot;else&quot;:1, &quot;enough&quot;:1, &quot;every&quot;:1, &quot;everywhere&quot;:1,<br>
 &nbsp; &nbsp;&quot;far&quot;:1, &quot;for&quot;:1, &quot;from&quot;:1,<br>
 &nbsp; &nbsp;&quot;here&quot;:1,<br>
 &nbsp; &nbsp;&quot;in&quot;:1, &quot;inside&quot;:1, &quot;into&quot;:1,<br>
 &nbsp; &nbsp;&quot;just&quot;:1,<br>
 &nbsp; &nbsp;&quot;last&quot;:1, &quot;lot&quot;:1, &quot;lots&quot;:1,<br>
 &nbsp; &nbsp;&quot;many&quot;:1, &quot;middle&quot;:1, &quot;much&quot;:1,<br>
 &nbsp; &nbsp;&quot;near&quot;:1, &quot;next&quot;:1, &quot;never&quot;:1, &quot;not&quot;:1, &quot;now&quot;:1, &quot;nowhere&quot;:1,<br>
 &nbsp; &nbsp;&quot;of&quot;:1, &quot;off&quot;:1, &quot;often&quot;:1, &quot;on&quot;:1, &quot;once&quot;:1, &quot;over&quot;:1, &quot;outside&quot;:1,<br>
&quot;over&quot;:1,<br>
 &nbsp; &nbsp;&quot;quite&quot;:1,<br>
 &nbsp; &nbsp;&quot;rather&quot;:1, &quot;recently&quot;:1, &quot;rarely&quot;:1, &quot;round&quot;:1,<br>
 &nbsp; &nbsp;&quot;seldom&quot;:1, &quot;sometimes&quot;:1, &quot;somewhere&quot;:1,<br>
 &nbsp; &nbsp;&quot;there&quot;:1, &quot;through&quot;:1, &quot;till&quot;:1, &quot;today&quot;:1, &quot;to&quot;:1, &quot;tomorrow&quot;:1,<br>
&quot;tonight&quot;:1, &quot;too&quot;:1, &quot;towards&quot;:1,<br>
 &nbsp; &nbsp;&quot;until&quot;:1, &quot;up&quot;:1, &quot;upstairs&quot;:1, &quot;usually&quot;:1, &quot;under&quot;:1,<br>
 &nbsp; &nbsp;&quot;very&quot;:1,<br>
 &nbsp; &nbsp;&quot;while&quot;:1, &quot;with&quot;:1, &quot;within&quot;:1, &quot;without&quot;:1,<br>
 &nbsp; &nbsp;&quot;yes&quot;:1, &quot;yesterday&quot;:1, &quot;yet&quot;:1,<br>
 &nbsp; &nbsp;&quot;you&quot;:1, &quot;he&quot;:1, &quot;she&quot;:1, &quot;it&quot;:1, &quot;we&quot;:1, &quot;they&quot;:1,<br>
 &nbsp; &nbsp;&quot;me&quot;:1, &quot;him&quot;:1, &quot;her&quot;:1, &quot;it&quot;:1, &quot;us&quot;:1, &quot;them&quot;:1,<br>
 &nbsp; &nbsp;&quot;myself&quot;:1, &quot;yourself&quot;:1, &quot;himself&quot;:1, &quot;herself&quot;:1, &quot;itself&quot;:1,<br>
&quot;ourselves&quot;:1, &quot;yourselves&quot;:1,<br>
 &nbsp; &nbsp;&quot;themselves&quot;:1, &quot;oneself&quot;:1,<br>
 &nbsp; &nbsp;&quot;my&quot;:1, &quot;your&quot;:1, &quot;its&quot;:1, &quot;our&quot;:1, &quot;their&quot;:1,<br>
 &nbsp; &nbsp;&quot;mine&quot;:1, &quot;yours&quot;:1, &quot;hers&quot;:1, &quot;ours&quot;:1, &quot;theirs&quot;:1,<br>
 &nbsp; &nbsp;&quot;this&quot;:1, &quot;these&quot;:1, &quot;those&quot;:1,<br>
 &nbsp; &nbsp;&quot;some&quot;:1, &quot;any&quot;:1, &quot;no&quot;:1, &quot;none&quot;:1,<br>
 &nbsp; &nbsp;&quot;other&quot;:1, &quot;another&quot;:1, &quot;every&quot;:1, &quot;all&quot;:1, &quot;others&quot;:1, &quot;each&quot;:1,<br>
&quot;whole&quot;:1, &quot;both&quot;:1,<br>
 &nbsp; &nbsp;&quot;neither&quot;:1, &quot;none&quot;:1,<br>
 &nbsp; &nbsp;&quot;someone&quot;:1, &quot;somebody&quot;:1, &quot;something&quot;:1,<br>
 &nbsp; &nbsp;&quot;anyoneanybodyanything&quot;:1,<br>
 &nbsp; &nbsp;&quot;nobody&quot;:1, &quot;nothing&quot;:1,<br>
 &nbsp; &nbsp;&quot;everyone&quot;:1, &quot;everybody&quot;:1, &quot;everything&quot;:1,<br>
 &nbsp; &nbsp;&quot;and&quot;:1, &quot;or&quot;:1, &quot;but&quot;:1, &quot;because&quot;:1, &quot;if&quot;:1,<br>
 &nbsp; &nbsp;&quot;as&quot;:1, &quot;like&quot;:1, &quot;such&quot;:1,<br>
 &nbsp; &nbsp;&quot;how&quot;:1, &quot;who&quot;:1, &quot;why&quot;:1, &quot;what&quot;:1, &quot;where&quot;:1, &quot;whose&quot;:1, &quot;when&quot;:1,<br>
&quot;whom&quot;:1, &quot;which&quot;:1,<br>
&quot;bye&quot;:1, &quot;hello&quot;:1,<br>
 &nbsp; &nbsp;&quot;be&quot;:1, &quot;was&quot;:1, &quot;been&quot;:1, &quot;am&quot;:1, &quot;is&quot;:1, &quot;are&quot;:1, &quot;were&quot;:1,<br>
 &nbsp; &nbsp;&quot;can&quot;:1, &quot;could&quot;:1,<br>
 &nbsp; &nbsp;&quot;come&quot;:1, &quot;came&quot;:1, &quot;comes&quot;:1,<br>
 &nbsp; &nbsp;&quot;do&quot;:1, &quot;did&quot;:1, &quot;done&quot;:1, &quot;does&quot;:1,<br>
 &nbsp; &nbsp;&quot;get&quot;:1, &quot;got&quot;:1, &quot;gets&quot;:1,<br>
 &nbsp; &nbsp;&quot;have&quot;:1, &quot;had&quot;:1, &quot;has&quot;:1, &quot;having&quot;:1,<br>
 &nbsp; &nbsp;&quot;may&quot;:1, &quot;might&quot;:1,<br>
 &nbsp; &nbsp;&quot;must&quot;:1,<br>
 &nbsp; &nbsp;&quot;shall&quot;:1, &quot;should&quot;:1,<br>
 &nbsp; &nbsp;&quot;ought&quot;:1,<br>
 &nbsp; &nbsp;&quot;take&quot;:1, &quot;took&quot;:1, &quot;taken&quot;:1, &quot;takes&quot;:1, &quot;taking&quot;:1,<br>
 &nbsp; &nbsp;&quot;use&quot;:1, &quot;uses&quot;:1, &quot;used&quot;:1,<br>
 &nbsp; &nbsp;&quot;will&quot;:1, &quot;would&quot;:1,<br>
 &nbsp; &nbsp;&quot;aren&#39;t&quot;:1,<br>
 &nbsp; &nbsp;&quot;cannot&quot;:1,<br>
 &nbsp; &nbsp;&quot;can&#39;t&quot;:1,<br>
 &nbsp; &nbsp;&quot;couldn&#39;t&quot;:1,<br>
 &nbsp; &nbsp;&quot;didn&#39;t&quot;:1,<br>
 &nbsp; &nbsp;&quot;doesn&#39;t&quot;:1,<br>
 &nbsp; &nbsp;&quot;don&#39;t&quot;:1,<br>
 &nbsp; &nbsp;&quot;wasn&#39;t&quot;:1,<br>
 &nbsp; &nbsp;&quot;wouldn&#39;t&quot;:1,<br>
 &nbsp; &nbsp;&quot;hadn&#39;t&quot;:1,<br>
 &nbsp; &nbsp;&quot;isn&#39;t&quot;:1,<br>
 &nbsp; &nbsp;&quot;one&quot;:1, &quot;two&quot;:1, &quot;three&quot;:1, &quot;four&quot;:1, &quot;five&quot;:1, &quot;six&quot;:1, &quot;seven&quot;:1,<br>
 &nbsp; &nbsp;&quot;eight&quot;:1, &quot;nine&quot;:1, &quot;ten&quot;:1, &quot;nought&quot;:1, &quot;zero&quot;:1,<br>
 &nbsp; &nbsp;&quot;first&quot;:1, &quot;second&quot;:1, &quot;third&quot;:1, &quot;fourth&quot;:1, &quot;fifth&quot;:1, &quot;sixth&quot;:1,<br>
&quot;seventh&quot;:1,<br>
 &nbsp; &nbsp;&quot;eighth&quot;:1, &quot;ninth&quot;:1, &quot;tenth&quot;:1,<br>
 &nbsp; &nbsp;&quot;ii&quot;:1, &quot;iii&quot;:1, &quot;iv&quot;:1, &quot;vi&quot;:1, &quot;vii&quot;:1, &quot;viii&quot;:1, &quot;ix&quot;:1,<br>
 &nbsp; &nbsp;&quot;sunday&quot;:1, &quot;monday&quot;:1, &quot;tuesday&quot;:1, &quot;wednesday&quot;:1, &quot;thursday&quot;:1,<br>
&quot;friday&quot;:1, &quot;saturday&quot;:1,<br>
 &nbsp; &nbsp;&quot;january&quot;:1, &quot;february&quot;:1, &quot;march&quot;:1, &quot;april&quot;:1, &quot;may&quot;:1, &quot;june&quot;:1,<br>
 &nbsp; &nbsp;&quot;julyaugustseptember&quot;:1, &quot;october&quot;:1, &quot;november&quot;:1, &quot;december&quot;:1,<br>
 &nbsp; &nbsp;&quot;date&quot;:1, &quot;false&quot;:1, &quot;e.geg&quot;:1, &quot;i.e&quot;:1, &quot;ie&quot;:1, &quot;etc&quot;:1, &quot;example&quot;:1,<br>
&quot;examples&quot;:1,<br>
 &nbsp; &nbsp;&quot;jrmiss&quot;:1, &quot;thing&quot;:1, &quot;things&quot;:1, &quot;true&quot;:1, &quot;year&quot;:1,<br>
 &nbsp; &nbsp;&quot;badbig&quot;:1, &quot;close&quot;:1, &quot;difficult&quot;:1, &quot;easy&quot;:1, &quot;empty&quot;:1, &quot;full&quot;:1,<br>
&quot;good&quot;:1,<br>
 &nbsp; &nbsp;&quot;little&quot;:1, &quot;long&quot;:1, &quot;ready&quot;:1, &quot;open&quot;:1, &quot;short&quot;:1, &quot;tall&quot;:1<br>
];<br>
}<br>
<br>
The map can be used in help for parsing English text. Now say we make this<br>
change:<br>
<br>
enum bool[string] stopWords = [ ... same contents ... ];<br>
<br>
Amazingly enough, looking up this new map (with &quot;word in stopWords&quot;) is many<br>
many times slower than looking up the old map. What&#39;s happening?<br>
<font color="#888888"><br>
<br>
--<br>
<br>
</font></blockquote></div><br>It may (and this is a big &quot;may&quot;, you&#39;d have to look at the disassembly to know) be related to <a href="http://d.puremagic.com/issues/show_bug.cgi?id=2237">http://d.puremagic.com/issues/show_bug.cgi?id=2237</a>.&nbsp; In short, I had a constant array (D1, same as an enum array in D2) which, for some reason, DMD was re-constructing the array from scratch upon _every access to it_ instead of putting it in the static data segment.&nbsp; It&#39;s possible that the compiler is making the same stupid mistake here.<br>
</div>