Actions Taking Longer than Expected Despite Logic for Exiting Early

Overview

This article explains a potential cause for Auth0 login and silent authorization requests that are taking longer than expected despite using actions that contain logic for exiting early.

Cause

A potential source of overhead is from instantiating libraries. For example, 'axios'. 

The following example code would always spend some time loading the axios library despite it not being called for a user who had a certain metadata flag:
const axios = require('axios')
exports.onExecutePostLogin = async (event, api) => {
    //check if user has a flag that indicates axios call is not required
    const metadataFlag = event.user.app_metadata.myCustomFlag
     if (metadataFlag) {
     // exit early
        return
    }

// perform axios call...
   
}

Solution

Moving the axios instantiation to a function that is called only if the correct criteria are met could be a way of reducing this overhead. 

The impact of the axios library is relatively small and only given for demonstration purposes, but other, larger libraries may have bigger impacts on runtimes.

For more performance tips, see Performance Best Practices.

Recommended content

No recommended content found...