Skip to content

⚡ [performance] optimize GCS file metadata fetching#102

Draft
max-ostapenko wants to merge 1 commit intomainfrom
optimize-gcs-metadata-fetch-18322883415643102784
Draft

⚡ [performance] optimize GCS file metadata fetching#102
max-ostapenko wants to merge 1 commit intomainfrom
optimize-gcs-metadata-fetch-18322883415643102784

Conversation

@max-ostapenko
Copy link
Contributor

💡 What:
Removed the file.exists() call in src/controllers/cdnController.js before calling file.getMetadata(). Wrapped file.getMetadata() in a try-catch to properly handle 404 errors when a file doesn't exist.

🎯 Why:
The previous code made two separate network requests to Google Cloud Storage (one to check existence, another to get the metadata). Since getMetadata() inherently checks for existence (throwing a 404 if missing), removing exists() reduces network overhead by exactly half for existing files without changing the functionality.

📊 Measured Improvement:
Created a mock benchmark (src/benchmarks/gcs_metadata.benchmark.js) simulating a 50ms GCS network delay.

  • Baseline (exists + getMetadata): ~10100ms for 100 requests.
  • Optimized (try-catch getMetadata): ~5030ms for 100 requests.
  • Improvement: 50.14% faster for requests where the file exists. For requests where the file does not exist, the performance is identical as both scenarios make exactly 1 network request.

PR created automatically by Jules for task 18322883415643102784 started by @max-ostapenko

Remove redundant `file.exists()` check and instead rely on catching a 404 error from `file.getMetadata()`. This saves an entire network roundtrip for existing GCS proxy files, halving the network overhead for serving these files. Included a benchmark script to quantify the improvement.
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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.

1 participant