Skip to content

Conversation

@williamdalessandro
Copy link
Contributor

@williamdalessandro williamdalessandro commented Nov 25, 2025

While looking for ways to optimize/shave off time from our builds, I was brought back to this ticket. This caching step didn't make any sense to me so I delved into it.

Essentially, this step was creating a cache key whose name was a mix between a hash of our package-lock file and a hash of all of our (70k+) mdx files (which would take 2-3 min to process). This key would be used to pull up a cached version of the content we have in ~/.npm and /.next/cache during the github runner process. The content in those folders are just downloaded packages, compliled js/ts files, and other things for nextjs optimization.

If a single mdx file changed, it would just invalidate the cache (even though the cache was totally good to use), and cause us to run npm install again, so we never really had the proper benefit of this cache in the first place.

This PR simplifies and narrows the scope of the files we actually care about caching the changes for. Included changes in both the build-preview process and the deploy-udr step.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 25, 2025

Vercel Previews Deployed

Name Status Preview Updated (UTC)
Dev Portal ✅ Ready (Inspect) Visit Preview Sat Dec 6 00:04:03 UTC 2025
Unified Docs API ✅ Ready (Inspect) Visit Preview Fri Dec 5 23:58:08 UTC 2025

@RubenSandwich
Copy link
Contributor

@williamdalessandro you are not going to see any changes in the workflow because of special security rules around the pull_request_target action trigger.

This event runs in the context of the base of the pull request, rather than in the context of the merge commit, as the pull_request event does. This prevents execution of unsafe code from the head of the pull request that could alter your repository or steal any secrets you use in your workflow. This event allows your workflow to do things like label or comment on pull requests from forks. Avoid using this event if you need to build or run code from the pull request.

For example notice in your latest commit, even though you removed the .next cache it is still listed: https://github.com/hashicorp/web-unified-docs/actions/runs/19686847781/job/56394394734#step:6:4.

You will need to duplicate the GHA workflow file with a trigger of just pull_request to see the changes in this PR, as pull_request_target will always use the main branches version of it's workflow for security reasons.

@williamdalessandro williamdalessandro marked this pull request as ready for review December 4, 2025 21:11
@williamdalessandro williamdalessandro requested a review from a team as a code owner December 4, 2025 21:11
@williamdalessandro
Copy link
Contributor Author

williamdalessandro commented Dec 4, 2025

Delved deeper into our build process and everything else we're doing but the biggest time sink comes from our interaction with vercel when we hand data off to them. At this point in time we're already handling that the best we can without doing large structural reorganizations.

Answers for why certain parts of the build process are slow or appear to be slow:

  • get changed files: this can be slow or fast- on average with pull_request it seems to be slower because apparently it has a larger search context to find the base branch to compare changes against

    • other times this can just be very slow in general, but we should see a speed up when it's brought to pull_request_target because the base branch is simply main
  • security check, left unchanged

  • deploy UDR docs api preview:

    • this one, saved 3 minutes by optimizing and actually fixing a caching step that wasn't being implemented correctly (this caching is really only for the gh action runners)

    • all the other slow parts are vercel calls that are already being done optimally

  • dev portal preview:

    • added the same cache optimization here, saved like 1 min

asyncMapFn,
{ batchSize = 16, loggingEnabled = true } = {
batchSize: 16,
{ batchSize = 64, loggingEnabled = true } = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return to testing if this is dependent on local machines thread count? Could this cause CPU thread switching trash?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only unknown here, but really don't know. 🤷🏻

Copy link
Contributor Author

@williamdalessandro williamdalessandro Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it's node and its batching promises, there's inherent protection against that because its limited to 4 threads based on the UV_THREADPOOL_SIZE parameter. So it's always handling 4 things at a time, but we'd just be handing it a bigger batch that's a bit more efficient, but also not going so crazy with the batch size that we hit other issues with memory pressure. So it should be fine to stay

Copy link
Contributor

@RubenSandwich RubenSandwich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

@williamdalessandro williamdalessandro merged commit 8fb5b8a into main Dec 6, 2025
17 checks passed
@williamdalessandro williamdalessandro deleted the optimizing-build-cache-step branch December 6, 2025 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants