Is there a difference in speed loading an app.R file with 5k lines vs dividing up into multiple scripts?

I have a single app.R file that runs several algorithms on user data - all of which are very well separated and organized in the file. One common approach I've seen is to divide this file up into ui, server, and other scripts (called using source() for example).

Does splitting one huge file into multiple have benefits beyond organization? If we disregard the fact that it's easier to work on the app in separated files - will it actually load faster?

The current file takes several moments just to chug through the several thousands of lines of code. Let's say 80% of the functions being performed aren't called until the user clicks a button within the app. Would the app be faster by calling these functions from an associated file rather than load them at once in the beginning?

Thanks!

Loading multiple scripts should be slightly slower than using a single file, due to the overhead of opening multiple files.

I just profiled the time for the example R-Studio shiny app from calling runApp to idle of the app:

Single file app: 700ms
Multiple files: 780ms

A difference of 80ms (on my system) should not really matter, regarding the server start.

1 Like