I have a tail recursive piece of code that could potentially call itself recursively up to thousands of times, and overall be executed up to millions of times each time the program is run. This raises some concerns regarding performance, and the size of the stack available to thinBasic.
That's why I have these questions:
  • Does thinBasic optimize/eliminate tail recursive calls?
  • If the answer to the previous is no, do I run the risk of overflowing the stack, if the function I'm talking about takes one potentially 240-character long string, one 6-character long string, and one dword as arguments?
  • Is there any profiling information available regarding the FILE_Exists function from the FILE module? My recursive function involves it, so it could be called millions of times as well. I would like to have even a rough estimate as to how long it takes.

This is the code:
uses "FILE"
$myseparator = "_-" 

Function uniquefilename(unsafe As String) As String
If Not FILE_Exists(unsafe) Then Return unsafe
Return sequencefilename(getpathandfilename(unsafe), getdotext(unsafe),0)
End Function

Function sequencefilename(filename As String, dotext As String,_
                          seqnum As DWord) As String
If Not FILE_Exists(filename & $myseparator & tob32(seqnum) & 
                   dotext) Then _
      Return filename & $myseparator & tob32(seqnum) & dotext                        
Return sequencefilename(filename,dotext,seqnum+1)
End Function
tob32 is a function that encodes a number as a base 32 string. As for the other functions, getpathandfilename and getdotext, well, you can probably imagine what they do.