0
0
GCPcloud~5 mins

Performance optimization in GCP - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Performance optimization
O(n)
Understanding Time Complexity

When we optimize performance in cloud systems, we want to know how the work grows as we add more tasks or users.

We ask: How does the time to complete tasks change when the workload increases?

Scenario Under Consideration

Analyze the time complexity of scaling a cloud function to handle multiple requests.


// Pseudocode for handling requests in GCP Cloud Functions
function handleRequests(requests) {
  for (let i = 0; i < requests.length; i++) {
    processRequest(requests[i]);
  }
}

function processRequest(request) {
  // Calls external API
  callExternalAPI(request.data);
}
    

This sequence processes each request by calling an external API once per request.

Identify Repeating Operations

Look at what repeats as the number of requests grows.

  • Primary operation: Calling the external API for each request.
  • How many times: Once per request, so as many times as there are requests.
How Execution Grows With Input

Each new request adds one more API call, so the total work grows steadily with the number of requests.

Input Size (n)Approx. Api Calls/Operations
1010 API calls
100100 API calls
10001000 API calls

Pattern observation: The work grows directly in proportion to the number of requests.

Final Time Complexity

Time Complexity: O(n)

This means the time to complete all requests grows in a straight line as the number of requests increases.

Common Mistake

[X] Wrong: "Adding more requests won't affect total time much because calls happen fast."

[OK] Correct: Each request adds a separate call, so total time adds up and grows with the number of requests.

Interview Connect

Understanding how work grows with input helps you explain system behavior clearly and shows you can think about scaling in real projects.

Self-Check

"What if we batch multiple requests into one API call? How would the time complexity change?"