<div dir="ltr"><div dir="ltr">On Tue, Jul 21, 2020 at 12:07 PM Jakob Reschke <<a href="mailto:forums.jakob@resfarm.de">forums.jakob@resfarm.de</a>> wrote:<br></div><div class="gmail_quote"><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">Hi Marcel,<br>
<br>
Might be cool if the JIT or Scorch emitted code that is equivalent to<br>
a quick return, but with a low-level nil-guard in place. Like a<br>
quick-return-if-not-nil primitive code.<br></blockquote><div><br></div><div>In TruffleSqueak, we profile how often a branch is taken. The init branch is only taken once, so it's unlikely to be part of the compiled code emitted by the JIT. The decrease in code size then makes it very likely that inlining is going to happen. Not sure if the OpenSmalltalkVM has similar optimizations for this in place.</div><div><br></div><div>Fabio</div><div> </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">
<br>
Is eager initialization out of the question for you?<br>
<br>
If all your instVars were initialized on the first read of one of<br>
them, you could also change the class of the object after the lazy<br>
initialization, and the new class would have quick accessors. For<br>
added fanciness, you could auto-generate the "optimized" class and<br>
such accessors in both classes. Though I am totally not sure whether<br>
it is worth the effort or improves the performance at all (since the<br>
call sites are then polymorphic).<br>
<br>
notYetInitialized: sounds strange to me, since you could send the<br>
getter in one place and actually use the answer in a totally different<br>
place (where your MNU happens). You could eager-initialize and return<br>
some special case proxy instead of nil that is bound to the original<br>
receiver and takes care of the lazy initialization when called.<br>
<br>
Kind regards,<br>
Jakob<br>
<br>
Am Di., 21. Juli 2020 um 10:36 Uhr schrieb Marcel Taeumel<br>
<<a href="mailto:marcel.taeumel@hpi.de" target="_blank">marcel.taeumel@hpi.de</a>>:<br>
><br>
> Hi all!<br>
><br>
> I can choose to initialize an instVar eagerly in #initialize or lazily in its accessor via #ifNil:. Yet, the latter requires me to change that accessor to something not being a quick return.<br>
><br>
> Could there be a simple way to initialize an instVar on its first read access? Like a #notYetInitialized: callback to the instVar-holding receiver. Instead, we get an MNU on UndefiniedObject ...<br>
><br>
> (Why? Performance reasons for a little project of mine.)<br>
><br>
> Best,<br>
> Marcel<br>
><br>
<br>
</blockquote></div></div>