Hi, Andy Wingo skribis: > On Wed 29 Apr 2020 22:22, Ludovic Courtès writes: > >> As discussed on IRC, the patch below arranges so that subrs that take >> strings and pass them to syscall wrappers can avoid the >> malloc/free/dynwind overhead. This gives a 10% speedup on a tight loop >> that calls these subrs: > > Neat optimization. Since it's internal, no problem from me. My concern > is only about calcifying aspects of our C / GC interface in API. > >> On IRC, Andy mentioned concerns that the SCM could disappear and thus, >> our the internal pointer returned by ‘scm_locale_string_data’ wouldn’t >> be enough to prevent the stringbuf from being GC’d. > > I would suggest doing the whole optimization and being sure to do > scm_remember_upto_here_1 on the SCM value at use sites. Here’s an updated patch that does that. The fallback case in ‘scm_locale_string_data’ is unfortunately not as nice as I wrote before, because it has to call ‘scm_to_stringn’, which mallocs the string, which must then be copied to GC-managed storage, argh. (The patch I sent earlier didn’t take care of the encoding conversion in the fallback case.) The libunistring functions can take a pre-allocated buffer, but they always malloc a fresh one if needed. So the best we could do is have a ‘scm_to_stringn’ variant that takes a buffer, but it’s not guaranteed that it’ll actually be used. All in all, it seems the added complexity is not warranted. The worst case of ‘scm_locale_string_data’ is also rare enough. Thoughts? Ludo’.