Configuring Memory and CPU for Vercel Functions

Learn how to set the memory / CPU of a Vercel Function.
Table of Contents

You can only configure memory and CPU for Serverless Functions, Edge Functions have a fixed memory limit.

The memory configuration of a function determines how much memory and CPU a function can use while executing. By default, on Pro and Enterprise, functions execute with 1769 MB (1 vCPU) of memory. On Hobby, they will always execute with 1024 MB (0.6 vCPU). You can change the default memory size for all functions in a project or set a custom memory size for individual functions.

You should consider the following points when changing the memory size of your functions:

  • Performance: Increasing memory size can improve the performance of your functions, allowing them to run faster
  • Cost: Serverless Functions are billed based on the function duration, which is affected by the memory size. While increasing the function CPU can increase costs if the function duration stays the same, the increase in CPU can also make functions execute faster. If your function executes faster, it is possible for it to incur less overall function duration usage. This is especially important if your function runs CPU-intensive tasks. See Pricing for more information on how function duration is calculated

Users on Pro and Enterprise plans can configure the default memory from 1769 MB (1 vCPU). Any custom memory size set on a per-function basis in the vercel.json file will take precedence over the default memory size set in the dashboard.

To change the default function memory size in the dashboard:

  1. Choose the appropriate project from your dashboard on Vercel
  2. Navigate to the Settings tab
  3. From the left side, select Functions
  4. In the Function CPU section, select your preferred memory size option:
    The Function CPU setting in a Vercel project's dashboard
    The Function CPU setting in a Vercel project's dashboard
  5. The change will be applied to all future deployments made by your team. You must create a new deployment for your changes to take effect

The memory size you select will also determine the CPU allocated to your Serverless Functions. The following table shows the memory and CPU allocation for each type:

TypeMemory / CPUUse
Basic1024 MB / 0.6 vCPUCost-effective option for lightweight apps and APIs. Default for Hobby.
StandardDefault1769 MB / 1 vCPUPredictable performance for production workloads.
Performance3009 MB / 1.7 vCPUsIncreased performance for latency-sensitive applications and SSR workloads.

Users on the Hobby plan can only use the default memory size of 1024 MB (0.6 vCPU). Hobby users cannot configure this size.

Project created before 2019-11-08T00:00:00.000Z have the default function memory size set to 1024 MB/0.6 vCPU for Hobby plan, and 3008 MB/1.67 vCPU for Pro and Enterprise plan. Although the dashboard may not have any memory size option selected by default for those projects, you can start using the new memory size options by selecting your preferred memory size in the dashboard.

To configure the memory size for individual functions up to the allowed limits for your plan:

  1. Use the functions property within your vercel.json config file
  2. Use a glob pattern to specify the path
  3. Specify an integer defining the memory size in MB for your Serverless Function (between 128 and 3009)

The order in which you specify file patterns is important. For more information, see Glob pattern.

vercel.json
{
  "functions": {
    "api/test.js": {
      "memory": 3009
    },
    "api/*.js": {
      "memory": 3009,
      "maxDuration": 30
    }
  }
}

To check the memory size of your functions in the dashboard, follow these steps:

  1. Find the project you want to review and select the Deployments tab
  2. Go to the deployment you want to review
  3. From the deployment overview, click on the Functions tab
  4. Select the function from the dropdown menu, and the memory size of the function will be displayed in the Memory Size section

To learn more about the maximum size of your function's memory, see Max memory size.

While memory / CPU size is not an explicitly billed metric, it is fundamental in how the billed metric of Function Duration is calculated.

You are charged based on the amount of time your Serverless Functions have spent computing responses to the requests they’ve received. This is calculated in GB-Hours, which is the memory allocated for each Function in GB x the time in hours they were running.

For example, if a function has 1.7 GB (1769 MB) of memory and is executed 1 million times at a 1-second duration:

  • Total Seconds: 1M * (1s) = 1,000,000 Seconds
  • Total GB-Seconds: 1769/1024 GB * 1,000,000 Seconds = 1,727,539.06 GB-Seconds
  • Total GB-Hrs: 1,727,539.06 GB-Seconds / 3600 = 479.87 GB-Hrs
  • The total Serverless Function Execution is 479.87 GB-Hrs.

To see your current usage, navigate to the Usage tab on your team's Dashboard and go to Serverless Functions > Duration. You can use the Ratio option to see the total amount of execution time across all projects within your team, including the completions, errors, and timeouts.

You can also view Invocations to see the number of times your Functions have been invoked. To learn more about the cost of Serverless Functions, see Serverless Function Pricing.

Last updated on May 10, 2024