提升效能
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
關於 gzip
這個用戶端程式庫要求所有 API 回應和解壓縮的 gzip 壓縮
而非您的資料
雖然此方法需要額外的 CPU 作業時間將結果解壓縮,
因此通常值得一試
部分回應 (欄位參數)
根據預設,伺服器會在處理要求後傳回完整的資源表示法。
為提高成效
您可以要求伺服器只傳送您真正需要的欄位,並改為取得「部分回應」。
如需要求部分回應,
在任何 API 方法中加入標準 Fields
參數。
這個參數的值會指定要傳回的欄位。
您可以將此參數與任何會傳回回應資料的要求搭配使用。
在以下程式碼片段中
系統會呼叫探索服務的 GetRest
方法。
Fields
參數的值已設為 description,title
。
因此,傳回的物件只會包含說明和標題欄位。
var service = new DiscoveryService();
var request = service.Apis.GetRest("calendar", "v3");
request.Fields = "description,title";
var result = request.Execute();
請注意如何使用逗號來分隔所需欄位
和斜線,用於表示父項欄位中包含的欄位。
Fields
參數還有其他格式設定選項。
詳情請參閱第 頁
一文。
部分更新 (修補)
如果您呼叫的 API 支援修補程式
即可避免在修改資源時傳送不必要的資料。
針對這些 API,您可以呼叫 Patch
方法並
提供您要為資源修改的引數。
如要進一步瞭解 patch 語意
請參閱「成效提示」頁面。
批次
如果您要傳送許多小型要求,
批次處理、
如此可將這些要求組合成單一 HTTP 要求。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003eThis document provides techniques to enhance your application's performance by reducing network costs and unnecessary data transfers.\u003c/p\u003e\n"],["\u003cp\u003eUtilize the \u003ccode\u003eFields\u003c/code\u003e parameter for partial responses, retrieving only the necessary data from the server.\u003c/p\u003e\n"],["\u003cp\u003eEmploy \u003ccode\u003ePatch\u003c/code\u003e for partial updates, sending only modified data when making changes to resources.\u003c/p\u003e\n"],["\u003cp\u003eLeverage batching to combine multiple small requests into a single HTTP request, reducing overhead.\u003c/p\u003e\n"],["\u003cp\u003eConsult the specific API documentation's "Performance Tips" page for detailed guidance on these techniques.\u003c/p\u003e\n"]]],[],null,["# Improve Performance\n\nThis document covers techniques you can use to improve the performance of your application.\nThe documentation for the specific API you are using should have a\nsimilar page with more detail on some of these topics.\nFor example, see the\n[Performance Tips page for the Google Drive API](/drive/performance).\n\nAbout gzip\n----------\n\n\nThis client library requests gzip compression for all API responses and unzips\nthe data for you.\nAlthough this requires additional CPU time to uncompress the results,\nthe tradeoff with network costs usually makes it worthwhile.\n\nPartial response (fields parameter)\n-----------------------------------\n\n\nBy default, the server sends back the full representation of a resource after processing requests.\nFor better performance,\nyou can ask the server to send only the fields you really need and get a *partial response* instead.\n\n\nTo request a partial response,\nadd the standard `Fields` parameter to any API method.\nThe value of this parameter specifies the fields you want returned.\nYou can use this parameter with any request that returns response data.\n\n\nIn the following code snippet,\nthe `GetRest` method of the Discovery service is called.\nThe value of the `Fields` parameter is set to `description,title`.\nAs a result, the returned object will include only the description and title fields. \n\n```gdscript\nvar service = new DiscoveryService();\nvar request = service.Apis.GetRest(\"calendar\", \"v3\");\nrequest.Fields = \"description,title\";\nvar result = request.Execute();\n \n```\n\n\nNote how commas are used to delimit the desired fields,\nand slashes are used to indicate fields that are contained in parent fields.\nThere are other formatting options for the `Fields` parameter;\nfor details, see the \"Performance Tips\" page\nin the documentation for the API you are using.\n\nPartial update (patch)\n----------------------\n\n\nIf the API you are calling supports patch,\nyou can avoid sending unnecessary data when modifying resources.\nFor these APIs, you can call the `Patch` method and\nsupply the arguments you wish to modify for the resource.\n\n\nFor more information about patch semantics,\nsee the \"Performance Tips\" page in the documentation for the API you are using.\n\nBatch\n-----\n\n\nIf you are sending many small requests you may benefit from\n[batching](/api-client-library/dotnet/guide/batch),\nwhich allows those requests to be bundled into a single HTTP request."]]