<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:large">Hi Marcel,  Hi Levente, Hi Christoph, Hi All,</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Sep 15, 2020 at 7:42 AM Marcel Taeumel <<a href="mailto:marcel.taeumel@hpi.de">marcel.taeumel@hpi.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div id="gmail-m_-7365497863131650874__MailbirdStyleContent" style="font-size:10pt;font-family:Arial;color:rgb(0,0,0)">
                                        Hi Christoph.<div><br></div><div>Performance. Change it, bench it, post the results here. :-) Please specify you machine and try it on a slow RaspPi, too.</div></div></div></blockquote><div><br></div><div class="gmail_default" style="font-size:large">I think it's a historical hold-over.  Here's the same method in Smalltalk-80 v2:</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">!Text methodsFor: 'comparing'!</div><div class="gmail_default" style="font-size:large">= anotherText</div><div class="gmail_default" style="font-size:large">    ^string = anotherText string! !</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">Changing it to read</div><div class="gmail_default" style="font-size:large">  <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>other isText ifTrue:<span class="gmail-Apple-tab-span" style="white-space:pre">  </span>[ ^string = other string and: [runs = other runs]].</div><div class="gmail_default" style="font-size:large"><span class="gmail-Apple-tab-span" style="white-space:pre">  </span>other isString ifTrue: [ ^string = other ].</div><div class="gmail_default" style="font-size:large"><span class="gmail-Apple-tab-span" style="white-space:pre">  </span>^false</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large"> is not going to affect performance noticeably (runs are typically shorter than the strings and Array comparison isn't particularly slow).  However, it corresponds much closer to my intuitive understanding of Texts.  If I wanted to see if two texts had the same characters I would use aText string = bText string.  I see Levente's comment. but I think he's just commenting the anomaly inherited from Smalltalk-80, not saying "it must be this way".  Am I right Levente?</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">So how bad is the performance?  I chose some texts (they happen to be in the help browser, and as such they represent representative large texts, which I think is what we're worried about for performance) via</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large"><div class="gmail_default"><font face="times new roman, serif">Text allInstances select: [:t| t size > 5000 and: [t runs runs size > (t size / 200)]]</font></div><div class="gmail_default"><br></div><div class="gmail_default">(why <font face="times new roman, serif">text runs runs size</font>?  Because <font face="times new roman, serif">text runs size = text size</font>.  <font face="times new roman, serif">text runs runs</font> answers the size of the array holding the lengths of each emphasis run)</div></div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">Then I benchmarked the comparison via</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large"><font face="times new roman, serif">"Using the existing method compare strings."</font></div><div class="gmail_default" style="font-size:large"><div class="gmail_default"><font face="times new roman, serif">| copy |</font></div><div class="gmail_default"><font face="times new roman, serif">copy := self first copy.</font></div><div class="gmail_default"><font face="times new roman, serif">[self first = copy] bench '186,000 per second. 5.39 microseconds per run. 0 % GC time.'</font></div><div class="gmail_default"><font face="times new roman, serif"><br></font></div><div class="gmail_default"><font face="times new roman, serif">"Estimate the additional cost of comparing runs in a typical text"</font></div><div class="gmail_default"><font face="times new roman, serif">| copy |</font></div><div class="gmail_default"><font face="times new roman, serif">copy := self first copy.</font></div><div class="gmail_default"><font face="times new roman, serif">[self first string = copy string and: [self first runs = copy runs]] bench '154,000 per second. 6.48 microseconds per run. 0 % GC time.'</font></div><div class="gmail_default"><font face="times new roman, serif"><br></font></div><div class="gmail_default"><font face="times new roman, serif">"Estimate the additional cost when there is some difference in emphasis"</font></div><div class="gmail_default"><font face="times new roman, serif">| copy |</font></div><div class="gmail_default"><font face="times new roman, serif">copy := self first copy.</font></div><div class="gmail_default"><font face="times new roman, serif">copy addAttribute: (TextColor color: Color red) from: copy size // 2 to: copy size.</font></div><div class="gmail_default"><font face="times new roman, serif">[self first string = copy string and: [self first runs = copy runs]] bench '187,000 per second. 5.36 microseconds per run. 0 % GC time.'</font></div></div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">What the second one shows is that including testing for runs worsens performance by about 20%.  For me that's acceptable.</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">What the third one shows is that if emphases do in fact differ the overhead is far less, because in the runs comparison there is a size comparison, and that fails without bothering to compare all the elements.</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">And of course the additional cost of comparing runs depends on how complex typical runs are.  Here's a histogram:</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large"><div class="gmail_default"><font face="times new roman, serif">| texts |</font></div><div class="gmail_default"><font face="times new roman, serif">texts := Text allInstances select: [:t| t size > 0].</font></div><div class="gmail_default"><font face="times new roman, serif">(10 to: 100 by: 10) collect:</font></div><div class="gmail_default"><font face="times new roman, serif"><span class="gmail-Apple-tab-span" style="white-space:pre">      </span>[:percentage|</font></div><div class="gmail_default"><font face="times new roman, serif"><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>{ percentage.</font></div><div class="gmail_default"><font face="times new roman, serif"><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>  (texts select: [:t| | ratio |</font></div><div class="gmail_default"><font face="times new roman, serif"><span class="gmail-Apple-tab-span" style="white-space:pre">              </span>ratio := t runs runs size / t size * 100.</font></div><div class="gmail_default"><font face="times new roman, serif"><span class="gmail-Apple-tab-span" style="white-space:pre">             </span>(ratio between: percentage - 10 and: percentage) and: [ratio ~= (percentage - 10)]]) size * 100.0 / texts size roundTo: 0.01} ]</font></div><div class="gmail_default"><font face="times new roman, serif">#(#(10 67.62) #(20 15.48) #(30 6.58) #(40 2.49) #(50 2.49) #(60 0.36) #(70 0.18) #(80 0.0) #(90 0.0) #(100 4.8))</font></div></div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">So most texts have very few emphases (typically one ;-).  Only 5.3% of texts have runs longer than half the size of the text.  So in most cases the slow down by adding the runs comparison to the mix will be less than the 20% overhead above.  The worst case is represented by benchmark two above, a large text compared against an identical copy.</div><div class="gmail_default" style="font-size:large"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div id="gmail-m_-7365497863131650874__MailbirdStyleContent" style="font-size:10pt;font-family:Arial;color:rgb(0,0,0)"><div>Best,</div><div>Marcel</div><div></div><blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-top:20px;margin-left:0px;padding-left:10px">
                        <p style="color:rgb(170,170,170);margin-top:10px">Am 10.09.2020 20:32:34 schrieb Thiede, Christoph <<a href="mailto:christoph.thiede@student.hpi.uni-potsdam.de" target="_blank">christoph.thiede@student.hpi.uni-potsdam.de</a>>:</p><div style="font-family:Arial,Helvetica,sans-serif">
<div id="gmail-m_-7365497863131650874divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif" dir="ltr">
<p>Hi all,</p>
<p><br>
</p>
<p>is there any old thread about the design discussion of how Text>>#= works? (It does not consider attributes for quality.) Has this decision ever been questioned?</p>
<p><br>
</p>
<p>Naively and without an overview of any existing components that could rely on this implementation, I would like to question it.</p>
<p>Why should <b>'foo' asText allBold</b> be equal to <b>'foo' asText addAttribute: TextURL new</b>? With the same logic, we could also say that two dictionaries are equal iff they have got the same keys ...</p>
<p><br>
</p>
<p>There is even a concrete client in the Trunk suffering from this design decision: Marcel's new FormInspector (and analogously, MorphInspector). It uses </p>
<div>TextFontReference with a <span style="font-size:12pt">FormSetFont to display a screenshot right in the inspector pane. Unfortunately, the pane is never updated automatically because even if the screenshot changes, the text morph thinks the old text would
 equal the new one. I'd like to fix that without hacking any workaround into the inspectors.</span></div>
<div><span style="font-size:12pt">Even though this inspector implementation is a bit unusual, in my opinion, it shows that the current Text >> #= implementation might not be a perfect solution.</span></div>
<div><span style="font-size:12pt"><br>
</span></div>
<div><span style="font-size:12pt">I'm looking forward to your opinions.</span></div>
<div><span style="font-size:12pt"><br>
</span></div>
<div><span style="font-size:12pt">Best,</span></div>
<div><span style="font-size:12pt">Christoph</span></div>
<p></p>
<div id="gmail-m_-7365497863131650874Signature">
<div id="gmail-m_-7365497863131650874divtagdefaultwrapper" dir="ltr" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<div name="divtagdefaultwrapper">
<div>
<div id="gmail-m_-7365497863131650874Item.MessagePartBody">
<div id="gmail-m_-7365497863131650874Item.MessageUniqueBody" style="font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont">
<div dir="ltr">
<div id="gmail-m_-7365497863131650874divtagdefaultwrapper"><span style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<div id="gmail-m_-7365497863131650874Signature">
<div style="margin:0px"><font style="font-family:Calibri,Arial,Helvetica,sans-serif,serif,EmojiFont"></font></div>
</div>
</span></div>
</div>
</div>
</div>
</div>
<div><span style="font-size:10pt;color:rgb(128,128,128)"></span></div>
</div>
</div>
</div>
</div>
</div></blockquote>
                                        </div></div><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div></div></div></div></div></div></div></div></div>