提升性能
bookmark_borderbookmark
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
gzip 简介
此客户端库会请求对所有 API 响应进行 gzip 压缩,并为您解压缩数据。
虽然这种方法需要一些额外的 CPU 时间来对结果进行解压缩,但考虑到节约的网络费用,通常还是很值得的。
部分响应(fields 参数)
默认情况下,处理完请求之后,服务器会发回资源的完整表示形式。
为了提高性能,您可以要求服务器仅发送您真正需要的字段,从而只接收部分响应。
如需请求部分响应,请将标准 Fields
参数添加到任何 API 方法。
此参数的值指定您要返回的字段。
对于返回响应数据的任何请求,您都可以使用此参数。
在以下代码段中,调用了 Discovery 服务的 GetRest
方法。
Fields
参数的值设置为 description,title
。
因此,返回的对象将仅包含“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,您可以在修改资源时避免发送不必要的数据。
对于这些 API,您可以调用 Patch
方法,并提供要为资源修改的参数。
如需详细了解补丁语义,请参阅您所用 API 文档中的“性能提示”页面。
批量
如果您要发送很多小请求,不妨使用批处理功能,将这些请求打包到单个 HTTP 请求中。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-11-30。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-11-30。"],[[["This document provides techniques to enhance your application's performance by reducing network costs and unnecessary data transfers."],["Utilize the `Fields` parameter for partial responses, retrieving only the necessary data from the server."],["Employ `Patch` for partial updates, sending only modified data when making changes to resources."],["Leverage batching to combine multiple small requests into a single HTTP request, reducing overhead."],["Consult the specific API documentation's \"Performance Tips\" page for detailed guidance on these techniques."]]],[]]