JavaScript Functions for Speed and Profit

The movie below is from one of our most popular demos from “Year in Review” at DevCon 2014. I was talking about what a breakthrough custom functions were back in 2004 and how they unlocked a whole new kind of code-sharing among FileMaker developers. JavaScript functions in FileMaker may unlock even more potential.

Jason Young introduced the idea of using JavaScript as a calculator–as a library of functions–instead of using it for perhaps the more obvious purpose of building interface elements. (Jason’s original article on this can be seen as part 1 of this post.) This gives us a huge opportunity to share and borrow code from the immense catalogue of JavaScript functions and examples.

FileMaker Custom Functions Forum

FileMaker engineers start posting custom functions to a public forum: March 2004

As just one example, we (Jason) rewrote the venerable “namwoB” function in JavaScript. namwoB was the first recursive functions I ever saw and was posted by Andy LeCates back in March of 2004. The title comes from Court Bowman’s name spelled backwards… which is all the functions does, rewriting a string of text in reverse. This simplicity makes it a great way to talk about the different kinds of recursion in FileMaker and what a faster version of the function might look like in JavaScript.

Our example file shows the same recursive custom functions done as a “stack” recursive function (limited to about 10k loops), as a “tail” recursive function (limited to 49,999 loops), and as a JavaScript function executed in a webviewer and then passed into a FileMaker script.

Download the example file

JavaScript Functions in FileMaker are Fast

Looping through 49,000 characters took our tail-recursive custom function almost 3 seconds.

The JavaScript version of the function looped through 10 times that much text–nearly 500,000 characters–in 3/10ths of a second.

And thanks to the improved fmp url in FileMaker 13, we can grab the results of functions like these quite easily. The movie below demos this and walks through our example file. It also gives a nice side-effect-demo of how webviewers get their own thread in FileMaker Pro and what that may mean for trying to measure performance.

Want more? Subscribe to SeedCode for more tips.

Tagged with →  

11 Responses to JavaScript Functions in FileMaker

  1. Thanks John. This is very cool and it makes me wonder about using Javascript to parse FMP fields using regular expressions, which is not easily done natively in FMP.

  2. Brian Schick says:

    Great stuff, as ever, John! It’s really wonderful to see the FileMaker community getting excited about the huge potential of JavaScript.

    On our end, we’ve been busy cooking up some new techniques we’ll be sharing soon as well. Looking forward to trading our best ideas and exploring new uses of JavaScript together as a community!

  3. Don Clark says:

    Thanks for posting this demo and making a video, John (and Jason). I appreciate how much time it takes to develop new techniques like this and then find the time to properly share them on the web. I’m sure the rest of the FM community likes it, too!

  4. Richard says:

    This is excellent. Maybe this will encourage Filemaker Inc. to include Javascript natively in Filemaker in some future version.

  5. David says:

    Hi I am trying to learn this technique but some how it is not working for me. I have tried sample file in FileMaker 13 and it crashes. In FileMaker 14 and 15 my Mac swaps memory as crazy and the system becomes unresponsive. I am using El Capitan. Could it be that Webkit is leaking memory? Any help will be appreciated. Thank you

    • seedcode says:

      Hi David, It requires 13.0v3 or higher so that may be the issue in 13. You can also probably get past the speed in 14 and 15 by using < 49K characters in the JS example. Start with a few hundred characters and you can still see how it works. (On my FM15 machine it hung the first time I opened it and tried 49K characters, after closing and re-opening FM15 it seems fine and does 49,999 characters in 0.39 seconds.)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share →
DayBack Calendar
DayBack's 30-day trial is unlocked so you can customize it and integrate it with your files.
Download DayBack and we'll send you a couple short emails with tips on how to modify it and use some of the coolest features.
Thank you! Please download: DayBack Calendar
Need More?
SeedCode tips & example files in your inbox
Need More?
SeedCode tips & example files in your inbox
Want More?
Be the first to see articles and tips like these
Download TimeZync and we'll send you a couple short emails with tips syncing your FileMaker Go files.
Thank you! Please download: TimeZync
Want More?
Be the first to see articles and tips like these