One of the best bang for your buck optimizations I did recently was add the following to our next.config.js (we're using V13):
const swcOptions = require('next/dist/build/swc/options')
const { getLoaderSWCOptions } = swcOptions
swcOptions.getLoaderSWCOptions = function (...args) {
const result = getLoaderSWCOptions(...args)
result.jsc.target = 'es2022'
return result
}
This overrides the target https://swc.rs/ uses from the default of es5 to es2022, which sped up our quite heavy app by up to 3X in hot code paths, just by using newer JS syntax instead of falling back to 'transpiled' versions. Unfortunately Next.JS doesn't allow setting the target directly. My hunch is that especially this syntax in our hot path was a big benefactor: function cloneAndSetProperty(obj, prop, value) {
return { ...obj, [prop]: value }
}