<div dir="auto">That sounds like a worthy experiment! </div><div dir="auto"><br></div><div dir="auto">I  guess that would look like having an inline macro’d up path that checks if it can get the job done that falls back to the general code?</div><div dir="auto"><br></div><div dir="auto">Last I checked, the overhead for this sort of c call was on the order of 10nanoseconds or less which seems like it’d be very unlikely to be a bottleneck, but do you have any natural or artificial benchmark programs that would show case this? </div><div dir="auto"><br></div><div dir="auto">For this sortah code, extra branching for that optimization could easily have a larger performance impact than the known function call on modern hardware.  (Though take my intuitions about these things with a grain of salt. )</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 4, 2023 at 9:50 PM Harendra Kumar <<a href="mailto:harendra.kumar@gmail.com">harendra.kumar@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I was looking at the RTS code for allocating small objects via prim ops e.g. newByteArray# . The code looks like:</div><div><br></div><div>stg_newByteArrayzh ( W_ n )<br>{<br></div><div>    MAYBE_GC_N(stg_newByteArrayzh, n);<br><br>    payload_words = ROUNDUP_BYTES_TO_WDS(n);<br>    words = BYTES_TO_WDS(SIZEOF_StgArrBytes) + payload_words;<br>    ("ptr" p) = ccall allocateMightFail(MyCapability() "ptr", words);</div><div><br></div><div>We are making a foreign call here (ccall). I am wondering how much overhead a ccall adds? I guess it may have to save and restore registers. Would it be better to do the fast path case of allocating small objects from the nursery using cmm code like in stg_gc_noregs?</div><div><br></div><div>-harendra<br></div></div>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
</blockquote></div></div>