<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Mar 1, 2023 at 11:38 PM Tobias Pape <<a href="mailto:Das.Linux@gmx.de">Das.Linux@gmx.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi<br>
<br>
<br>
> On 1. Mar 2023, at 22:23, karl ramberg <<a href="mailto:karlramberg@gmail.com" target="_blank">karlramberg@gmail.com</a>> wrote:<br>
> <br>
> Hi <br>
> Mines game got really sluggish on a old laptop with i3 processor.<br>
> I tracked it down to this method where we copy protoTile instance variable<br>
> <br>
> MineBoard>>adjustTiles<br>
> "reset tiles"<br>
> <br>
> | newSubmorphs count r c |<br>
> <br>
> submorphs do: "clear out all of the tiles."<br>
> [:m | m privateOwner: nil].<br>
> <br>
> newSubmorphs := OrderedCollection new.<br>
> <br>
> r := 0.<br>
> c := 0.<br>
> count := columns * rows.<br>
> <br>
> 1 to: count do:<br>
> [:m |<br>
> newSubmorphs add:<br>
> (protoTile copy "Change this to MinesTile new to speed up"<br>
> position: self position + (self protoTile extent * (c @ r));<br>
> actionSelector: #tileClickedAt:newSelection:modifier:;<br>
> arguments: (Array with: (c+1) @ (r+1));<br>
> target: self;<br>
> privateOwner: self).<br>
> c := c + 1.<br>
> c >= columns ifTrue: [c := 0. r := r + 1]].<br>
> submorphs := newSubmorphs asArray.<br>
> <br>
<br>
So is the protoTile Morph supposed to have depdendents or submorphs itself?<br>
Morphs seem a tad heavy to copy en masse.<br>
Non-Morph objects are pretty lightweight (see shallowCopy/postCopy)<br>
<br>
Given these tiles ought to be quite independent and small, I really do not see why <br>
driving them through the dependents fixup.<br>
<br>
So one could simply really use a new, empty tile.<br>
<br>
That said, why are the "old" ones thrown out, anyway?<br>
<br>
I've skimmed the code and am actually puzzled.<br>
The dependency-fixup is roughly the same age as the Mines game. <br>
So either the Mines-Game author did not notice that slowdown or Instance creation was waaaaaay more expensive back then...<br></blockquote><div><br></div><div>SameGame and Mines have some really peculiar code. And there are subclassing and reuse instance variables that make it hard to follow. <br></div><div>If you run a course on  refactoring, it could be a good introduction project to document and make sense of this code :-D</div><div><br></div><div>Best,</div><div>Karl</div><div><br></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Best regards<br>
        -Tobias<br>
<br>
<br>
> <br>
> Here is MessageTally:<br>
> <br>
> [                        67.5% {8826ms} MinesBoard>>adjustTiles<br>
> [                          67.5% {8824ms} MinesTile(Morph)>>copy<br>
> [                            67.5% {8824ms} MinesTile(Object)>>veryDeepCopy<br>
> [                              66.6% {8713ms} DeepCopier>>fixDependents<br>
> [                                66.6% {8713ms} WeakIdentityKeyDictionary(WeakKeyDictionary)>>associationsDo:<br>
> [                                  64.3% {8404ms} primitives<br>
> [                                  2.2% {289ms} [] DeepCopier>>fixDependents<br>
> [                                    1.7% {222ms} DependentsArray>>do:<br>
> [                                      1.1% {139ms} primitives<br>
> <br>
> Best,<br>
> Karl <br>
> <br>
<br>
<br>
<br>
</blockquote></div></div>