ปรับปรุงประสิทธิภาพ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เอกสารนี้ครอบคลุมเทคนิคที่คุณสามารถใช้เพื่อปรับปรุงประสิทธิภาพของแอปพลิเคชันของคุณ
เอกสารประกอบสำหรับ API ที่คุณใช้ควรมี
หน้าที่คล้ายกันที่มีรายละเอียดเพิ่มเติมเกี่ยวกับหัวข้อเหล่านี้
ตัวอย่างเช่น โปรดดู
หน้าเคล็ดลับด้านประสิทธิภาพสำหรับ Google Drive API
เกี่ยวกับ gzip
ไลบรารีของไคลเอ็นต์นี้ขอการบีบอัด gzip สำหรับการตอบสนองและการแตกไฟล์ของ API ทั้งหมด
ข้อมูลให้คุณ
แม้ว่าวิธีนี้จะต้องใช้เวลา CPU เพิ่มเติมเพื่อยกเลิกการบีบอัดผลลัพธ์
การแลกกับค่าใช้จ่ายเครือข่ายมักจะคุ้มค่า
การตอบกลับบางส่วน (พารามิเตอร์ช่อง)
โดยค่าเริ่มต้น เซิร์ฟเวอร์จะส่งการแสดงผลแบบเต็มของทรัพยากรกลับมาหลังจากประมวลผลคำขอ
เพื่อประสิทธิภาพที่ดีขึ้น
คุณสามารถขอให้เซิร์ฟเวอร์ส่งเฉพาะช่องที่คุณต้องการจริงๆ แล้วรับการตอบกลับบางส่วนแทน
หากต้องการขอให้ตอบกลับบางส่วน
เพิ่มพารามิเตอร์ Fields
มาตรฐานลงในเมธอด API ใดก็ได้
ค่าของพารามิเตอร์นี้จะระบุช่องที่คุณต้องการให้แสดงผล
คุณใช้พารามิเตอร์นี้กับคำขอใดก็ได้ที่แสดงข้อมูลการตอบกลับ
ในข้อมูลโค้ดต่อไปนี้
มีการเรียกใช้เมธอด GetRest
ของบริการ Discovery
ค่าของพารามิเตอร์ 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 ที่คุณกำลังเรียกใช้รองรับแพตช์
คุณหลีกเลี่ยงการส่งข้อมูลที่ไม่จำเป็นเมื่อแก้ไขทรัพยากรได้
สำหรับ API เหล่านี้ คุณสามารถเรียกใช้เมธอด Patch
และ
ให้อาร์กิวเมนต์ที่คุณต้องการแก้ไขสำหรับแหล่งข้อมูล
ดูข้อมูลเพิ่มเติมเกี่ยวกับแพตช์เชิงอรรถศาสตร์
โปรดดูที่ "เคล็ดลับประสิทธิภาพ" ในเอกสารประกอบสำหรับ API ที่คุณใช้
กลุ่ม
หากคุณส่งคำขอเล็กๆ น้อยๆ เป็นจำนวนมาก คุณอาจได้รับประโยชน์จาก
แบบกลุ่ม
ซึ่งทำให้คำขอเหล่านั้นรวมกลุ่มอยู่ในคำขอ HTTP เดียวได้
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\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."]]