'How to inline a GAS library to speed up script?

The documentation for libraries states that they should be avoided in order to speed up the script. Is there a way to inline a library? I assume that there should be a way if the sources are available? Will just copy&pasting the sources of the library into my main script work?



Solution 1:[1]

Copy 'n paste should work, given you don't have any name conflicts. But you'll have to rename all the calls to your library removing the library name.

It's probably possible to create a constructor function to keep the namespace exactly the same. So you could you use the library or paste its code without changing the rest of the script.

Anyway, I think the documentation is a little harsh about this "speed improvement" of not using libraries. It's not that your script will run faster without a library, it'll just take a little less time to load. I think this is only relevant to do if you're writing addons or some massively used script with lots of UI interactions, etc.

Solution 2:[2]

I know this is an old thread, but it seems relevant still, so I'll post my thoughts on this :) (bear in mind that this is no expert opinion though and more of a thought as to why the docs. are warning us).

Using a library doesn't seem to have a noticeable effect on my scripts. But my thought is that if I don't use them sparingly I will, over time, start to see a degradation in running times.

This would be due to my scripts using libraries, that in turn use some other libraries, that still use other libraries. It will quickly become library hell, if we're not being careful.

So let's adhere to the warnings and use libraries cautiously. Then everyone will be happy and hell will wait another day.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Henrique G. Abreu
Solution 2 davido