Repository: tailwindlabs/tailwindcss
File: packages/@tailwindcss-postcss/src/index.ts (TypeScript)

Code before:
            let tailwindCssAst = compiler.build(candidates)
            DEBUG && I.end('Build utilities')

            if (context.tailwindCssAst !== tailwindCssAst) {
              if (optimize) {
                DEBUG && I.start('Optimization')

                DEBUG && I.start('AST -> CSS')
                let css = toCss(tailwindCssAst)
                DEBUG && I.end('AST -> CSS')

                DEBUG && I.start('Lightning CSS')
                let optimized = optimizeCss(css, {
                  minify: typeof optimize === 'object' ? optimize.minify : true,
                })
                DEBUG && I.end('Lightning CSS')

                DEBUG && I.start('CSS -> PostCSS AST')
                context.optimizedPostCssAst = postcss.parse(optimized.code, result.opts)
                DEBUG && I.end('CSS -> PostCSS AST')

                DEBUG && I.end('Optimization')
              } else {
                // Convert our AST to a PostCSS AST
                DEBUG && I.start('Transform Tailwind CSS AST into PostCSS AST')
                context.cachedPostCssAst = cssAstToPostCssAst(tailwindCssAst, root.source, postcss)
                DEBUG && I.end('Transform Tailwind CSS AST into PostCSS AST')
              }
            }

            context.tailwindCssAst = tailwindCssAst

            DEBUG && I.start('Update PostCSS AST')
            root.removeAll()
            root.append(
              optimize
                ? context.optimizedPostCssAst.clone().nodes
                : context.cachedPostCssAst.clone().nodes,
            )

            // Trick PostCSS into thinking the indent is 2 spaces, so it uses that
            // as the default instead of 4.
            root.raws.indent = '  '
            DEBUG && I.end('Update PostCSS AST')

            DEBUG && I.end(`[@tailwindcss/postcss] ${relative(base, inputFile)}`)
          } catch (error) {
            // An error requires a full rebuild to fix
            context.compiler = null

            // Ensure all dependencies we have collected thus far are included so that the rebuild

Review comment (performance):
```suggestion
                context.cachedPostCssAst = cssAstToPostCssAst(postcss, tailwindCssAst, root.source)
```

Code after:
            let tailwindCssAst = compiler.build(candidates)
            DEBUG && I.end('Build utilities')

            if (context.tailwindCssAst !== tailwindCssAst) {
              if (optimize) {
                DEBUG && I.start('Optimization')

                DEBUG && I.start('AST -> CSS')
                let css = toCss(tailwindCssAst)
                DEBUG && I.end('AST -> CSS')

                DEBUG && I.start('Lightning CSS')
                let optimized = optimizeCss(css, {
                  minify: typeof optimize === 'object' ? optimize.minify : true,
                })
                DEBUG && I.end('Lightning CSS')

                DEBUG && I.start('CSS -> PostCSS AST')
                context.optimizedPostCssAst = postcss.parse(optimized.code, result.opts)
                DEBUG && I.end('CSS -> PostCSS AST')

                DEBUG && I.end('Optimization')
              } else {
                // Convert our AST to a PostCSS AST
                DEBUG && I.start('Transform Tailwind CSS AST into PostCSS AST')
                context.cachedPostCssAst = cssAstToPostCssAst(postcss, tailwindCssAst, root.source)
                DEBUG && I.end('Transform Tailwind CSS AST into PostCSS AST')
              }
            }

            context.tailwindCssAst = tailwindCssAst

            DEBUG && I.start('Update PostCSS AST')
            root.removeAll()
            root.append(
              optimize
                ? context.optimizedPostCssAst.clone().nodes
                : context.cachedPostCssAst.clone().nodes,
            )

            // Trick PostCSS into thinking the indent is 2 spaces, so it uses that
            // as the default instead of 4.
            root.raws.indent = '  '
            DEBUG && I.end('Update PostCSS AST')

            DEBUG && I.end(`[@tailwindcss/postcss] ${relative(base, inputFile)}`)
          } catch (error) {
            // An error requires a full rebuild to fix
            context.compiler = null

            // Ensure all dependencies we have collected thus far are included so that the rebuild