Q: Why does the first response takes more time in GAS web app? Edit: I am using clasp. Updated the code to the actual GAS!
I have a GAS deployed as a web app. We send POST requests from Slack via a slash command and it needs a response in less than 3000ms because GAS can't handle asynchronous code.
At the first request, it takes more than 3000ms to send a response but on the following requests, it is around 1500ms.
The doPost function looks like the following.
var exports = exports || {};
var module = module || { exports: exports };
Logger = BetterLog.useSpreadsheet('spreadsheetId');
function doPost(request) {
    var startExecutionDate = new Date();
    var path = request.parameter.path;
    Logger.log("Request received with path: " + path);
    var response = Responses.Error;
    var token = request.parameter.token;
    if (path.startsWith('/slack')) {
        Logger.log("Slack request");
        var slackRouter = new SlackRouter();
        response = slackRouter.post(request);
        // ...
    }
    // ...
}

And this is the code for the Slack Router.
var exports = exports || {};
var module = module || { exports: exports };
var SlackRouter = (function () {
    function SlackRouter() {
    }
    SlackRouter.prototype.post = function (request) {
        var path = request.parameter.path;
        switch (path) {
            case Routes.Team:
                Logger.log("For team");
                // ...
        }
    };
    return SlackRouter;
}());
exports.SlackRouter = SlackRouter;

I have the timestamps for each log.
First attempt
| Timestamp    | Delta in ms | Log Message   |
|--------------|-------------|---------------|
| 11:22:34:164 | 0           | Path: ...     |
| 11:22:35:354 | 1190        | Slack request |
| 11:22:35:462 | 108         | For team      |

Second attempt
| Timestamp    | Delta in ms | Log Message   |
|--------------|-------------|---------------|
| 11:22:45:047 | 0           | Path: ...     |
| 11:22:45:164 | 117         | Slack request |
| 11:22:45:350 | 186         | For team      |

I had several ideas already like the web app goes to a sleep state but since we calculate delta from the first log message it doesn't make sense.
So what is going on behind the scenes? Are you aware of any easy workarounds? If possible I don't want to build a microservice to send a response to Slack in time and later send the actual response.

A: 
The Apps Script servers don't keep every script ever written or deployed loaded in memory, and so scripts that haven't been run in a while need to be loaded from disk first. This is usually referred to as a "cold start time" in Cloud providers.

Answered by Eric Koleda on Google Apps Script Community forum

A: The most glaring issue is your use of ES6 syntax in your doPost() method. 
Google Apps Script does not support ES6 template string syntax and only partially supports destructuring assignments. So that might be your issue. Your doPost() probably fails to return a value as a result so Slack likely repeats the request until it times out.

A: Try removing the BetterLog library. That may be causing the initial first-time delay. 
https://developers.google.com/apps-script/guides/libraries
Warning: A script that uses a library does not run as quickly as it would if all the code were contained within a single script project. Although libraries can make development and maintenance more convenient, you should use them sparingly in projects where speed is critical. Because of this issue, library use should be limited in add-ons.
