FM18 while function vs recursive custom functions performance question

newly introduced WHILE function is a nice feature of FM18. How does it perform in comparison to a semantically equivalent recursive custom function?

1 Like

I wish I had an answer for you, as we use it extensively, but are too busy to replicate the While procedures either within a custom function or script steps to compare.

Although not answering your question, what I do like is that the code is in front of me within the script and not hidden elsewhere. While creating or debugging I’m not trying to replicate a recursive custom function within the data viewer, but can lift the code directly and display various stages of results.

In layman’s terms, we’ve been very impressed with performance, but no comparison data to offer I’m afraid.

Good question. I only started using the while function. Debugging is more challenging in the function editor. That’s why I implement complex things in script first. Once I run across a good case for comparison, I may post about.

I did not arrive on FMP18 yet - at least not above testing, but I use MBS.Loop instead of custom functions for at least two years now … and I love it compared to custom functions although I sometimes struggle with the code to be evaluated because that has to be in english, other languages are not supported at this time.
I’ll give “while” a try but it is more out of curiosity…

…and thinking about it, since this is not Runtime-compatible, time would be wasted for me, same as with JSON stuff, this is strictly MBS only

@FabriceN at 1-more-thing ?

I will soon start my own metrics by comparing slow recursions with while and if while has been proven to be faster I will replace a lot of my CFs with it (if applicable).

To refine my question I would like to know if found set scanning via recursive GetNthRecord (or portal row scanning) outperforms recursion when WHILE used instead.

Intuitively I would guess WHILE should be faster because of call-stack handling assuming WHILE is not underthehood implemented as a recursion - which could be suspected due to same loop limit of default 50k iterations …

In other words - that WHILE and embedded recursive CFs both can be managed with the SetRecursion function kind of implies that WHILE is ‘compiled’ by FM’s calc-eninge into a recursive substitute? Would be great if someone at Claris who implemented it could tell.

1 Like

I swear I had seen someone post something about tests they ran, but I can’t find it now. I could only find a semi-related article about While () calc speed vs a scripted loop.

I’ve compared just a few CFs recursion vs. while. My finding is, while is just a tiny bit faster but not so much to start converting. Once used to the recursion code structure, I still like it more than the while, more compact and I still like to use “CustomList” to generate lists…


The other test we wish to try is to compare While against looping scripts, but again time is against us at the moment.

Thank You, Otmar!

There were somewhere some other tests/findings, but could not find that anymore.

We did also some tests, but not concerning speed/diff’s, more concerning the handling

Mostly the ‘naming’ did not sound here (german version). Why not just name it ‘while’? It is not more difficult to learn ‘while’ instead of ‘solange’… not one single human programmer knows what ‘solange’ means

@Markus, regarding the naming: I anyway would encourage anyone to use FM in english for coding, no one would code c++, swift, c#… in a translated version. There’re a lot of other funny words in the translation, solange might not be the worst;-)


Yes, all true - but not an easier life if You are doing coaching, courses in German…

‘SetzeVar’ is one of the worst, was changed from ‘SetzeVars’ (they stripped the last ‘s’, leaving quite some CF out…)

Yes, that makes it a bit harder. It would be nice if we could just switch the coding language, not the whole interface language…

that would be great!

btw. See You in Hamburg next week, FileMaker-Konferenz?

Yes, I’ll be there, so see you soon!

@AndyHibbs check out article on comparing While ( ) to a looping script.


Unfortunately I don’t remember the particulars (the demonstration was too fast for me) but some performance hit were found in certain use case and limits when comparing while with a cf. I know it doesn’t help much…

1 Like

At one point I did test CustomList ( ) against a similar While ( ) calc. CustomList was approximately 10-15% faster, on lists of about 25 characters per value. There was some variance between 1000 - 100000 iterations. I am pretty sure I lost that file ( mystery case of my Downloads folder emptying itself ). The use of immutable variables in CustomList is a large part of where it gets it’s speed from.


Thanks Josh, useful info and the use of While and JSON is something we’re finding works well.

I can confirm that CustomList() is still faster for some things like @jormond described because it’s doesn’t use basic recursion. I haven’t actually tested any recursion yet either, but I’ve tested loops.

Simple Loop Test

Doing an empty loop in While is much faster than a scripted loop. (see picture below for the script). (Time in milliseconds):

Reps While Loop
100000 362 4287

Appending Values Test

And since Josh brought up variable mutability, appending values to a list in While() is not necessarily faster than a scripted loop because scripts can use Insert Calculated Result to append values. This becomes very pronounced as the list size grows. While still wins for small lists, but this is likely due to the extra overhead of a scripted loop as measured in the previous test.

Reps While Loop
1000 18 40
10000 389 408
20000 1102 804
30000 2235 1276