Using my Script Libraries as handler dispensers

What’s the worst that could happen if I stop using my libraries and just duplicate their handlers, and any handlers they are dependent on, into my scripts?

The problem I’m running up against is that I frequently hit AppleScript’s stack limit on larger scripts. I’ve broken my libraries up by function category or application that they address, but If I need one handler from each of the FileSystem, Array, String, Photoshop, and Math libraries, I have to load ALL of those libraries’ handlers. Some of my libraries are large, and I’m usually using only a fraction of their handlers in any given script. But all of their code is loaded into the script context. It seems like the obvious solution is to further segment my libraries so I can load less unused code. But I’m currently at 19 libraries. This led me to think that the extreme version of this solve would be single-handler libraries. Madness!

Instead, I’ve written a script that lets me choose one of my libraries, and then it presents that library’s handlers for me to choose from. It inserts a call to a chosen handler into the front Script Debugger document at the current cursor position, if the handler is new to the script then it jumps to the end of the script and inserts the handler’s source code. It checks the newly added handler for any dependencies and loads those handlers, recursively checking each one for dependencies, and then returns to the original cursor position. Done. This way, I have easy access to any of my handlers, but only the necessary code is loaded into the script context.

This has completely resolved my issues with the memory stack issue. Now I’m trying to imagine any possible pitfalls that I’m digging for my future self.

If a handler in one of my libraries gets updated, I’d have to replace that handler in every script that uses it to get it to use the new code. On the upside, existing scripts will be absolutely stable and won’t alter their behavior if a library changes. This is a wash as far as I’m concerned. Most of my scripts have limited lifespans, and those that are persistent will continue to work just as they are. If a script must be updated then I have a script that can easily replace the handlers’ code in it for me.

This is only for my own script libraries, third party libs would still be used normally. So, what could I run into later that I’ll wish I’d thought of? Worst-case scenarios are appreciated here.