<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>I don't see any type specs in srfi 13 for substring/shared so I doubt very much that the slowdown has anything to do with TR. Avoid jumping to conclusions or explain more so we can judge the problem. If you are writing code in TR, run it thru Vincent's feature profiler to find out whether it really is the string? predicate generated from the String type. Also consider conducting a small 'untyped' experiment. If it is the contract, please do report back. </div><div><br></div><div>-- Matthias</div><div><br></div><div><br></div><div><br></div><div><br></div><br><div><div>On Apr 4, 2014, at 10:23 PM, Spencer florence wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span id="mailbox-conversation">Unfortunately that eventually does require running the true substring operation. All of my substrings are short-lived values that are used immediately, so being lazy doesn't help much. My issue is that Im running substring several million times to generate very short-lived values that are almost immediately ready to be collected.<div><br></div>
<div>substring/shared does seem to be what I want, although for some reason using that instead of substring is actually much  (~30%) slower. My initial guess as to why is TR contract boundary shenanigans, although that also seems odd given that the only contract that should be generated by requiring substring/shared is string?.</div></span><br><br><div class="gmail_quote"><p>On Fri, Apr 4, 2014 at 4:12 PM, John Clements <span dir="ltr"><<a href="mailto:clements@brinckerhoff.org" target="_blank">clements@brinckerhoff.org</a>></span> wrote:<br></p><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>On Apr 3, 2014, at 7:08 PM, Spencer Florence <<a href="mailto:spencer@florence.io">spencer@florence.io</a>> wrote:
<br><br>> Is there any way to perform `substring` without creating a new string? I'm working with lots of very large and (for all intents and purposes) immutable strings and would like to avoid the extra allocations and copy time.
<br><br>Seems like it would be fairly easy to roll this yourself:
<br><br>#lang racket
<br><br>(require rackunit)
<br><br>;; represent a lazy substring operation:
<br>(struct lazysubstring (str start end))
<br><br>;; force a lazy substring
<br>(define (lss-force s)
<br>  (substring (lazysubstring-str s)
<br>             (lazysubstring-start s)
<br>             (lazysubstring-end s)))
<br><br>;; get the length of a lazy substring:
<br>(define (lss-len s)
<br>  (- (lazysubstring-end s) (lazysubstring-start s)))
<br><br>;; create one:
<br>(define source-text "othho tot stnh ontuh .nt")
<br><br>(define lss1 (lazysubstring source-text 3 9))
<br>(check-equal? (lss-len lss1) 6)
<br><br>Obviously, you have to “roll your own” for any operation that you want to perform that retains the laziness.
<br><br>John
<br><br></blockquote></div><br>____________________<br>  Racket Users list:<br>  <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>