Zwiększ skuteczność
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Informacje o gzip
Ta biblioteka klienta żąda kompresji gzip w przypadku wszystkich odpowiedzi interfejsu API i rozpakowywania
za Ciebie.
Chociaż zdekompresowanie wyników wymaga dodatkowego czasu pracy procesora,
kompromis z kosztami sieciowymi zwykle jest opłacalny.
Odpowiedź częściowa (parametr pól)
Po przetworzeniu żądań serwer domyślnie odsyła pełną reprezentację zasobu.
Aby zwiększyć wydajność,
możesz poprosić serwer, by wysłał tylko te pola, których potrzebujesz, i uzyskał odpowiedź częściową.
Aby poprosić o odpowiedź częściową:
dodaj standardowy parametr Fields
do dowolnej metody interfejsu API.
Wartość tego parametru określa pola, które mają być zwracane.
Tego parametru możesz używać w każdym żądaniu, które zwraca dane odpowiedzi.
W tym fragmencie kodu
wywoływana jest metoda GetRest
usługi wykrywania.
Wartość parametru Fields
jest ustawiona na description,title
.
W rezultacie zwrócony obiekt będzie zawierał tylko pola opisu i tytułu.
var service = new DiscoveryService();
var request = service.Apis.GetRest("calendar", "v3");
request.Fields = "description,title";
var result = request.Execute();
Zwróć uwagę, jak przecinki służą do oddzielania wybranych pól.
i ukośniki służą do wskazywania pól znajdujących się w polach nadrzędnych.
Dostępne są też inne opcje formatowania parametru Fields
.
szczegóły można znaleźć w sekcji „Wskazówki dotyczące skuteczności” strona
znajdziesz w dokumentacji używanego interfejsu API.
Częściowa aktualizacja (poprawka)
Jeśli wywoływany interfejs API obsługuje poprawkę,
możesz uniknąć wysyłania niepotrzebnych danych
podczas modyfikowania zasobów.
W przypadku tych interfejsów API możesz wywołać metodę Patch
i
podaj argumenty, które chcesz zmienić dla zasobu.
Więcej informacji o semantyce poprawki znajdziesz w artykule
przeczytaj „Wskazówki dotyczące skuteczności”, znajdziesz w dokumentacji używanego interfejsu API.
Wsad
Jeśli wysyłasz wiele małych próśb, możesz odnieść korzyści
łączeniu wsadowe,
który pozwala połączyć te żądania w jedno żądanie HTTP.
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-07-26 UTC.
[null,null,["Ostatnia aktualizacja: 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."]]