技能 编程开发 Grammarly API性能优化

Grammarly API性能优化

v20260423
grammarly-performance-tuning
本技能旨在指导如何优化Grammarly API的调用性能,解决API响应慢、处理效率低的问题。内容涵盖了实现缓存策略(如LRUCache)以存储结果,以及利用JavaScript的并行处理机制(Promise.all)同时发起多个API调用,从而显著提高系统的处理吞吐量和实时性。
获取技能
141 次下载
概览

Grammarly Performance Tuning

Latency Benchmarks

API Typical Latency Notes
Writing Score 1-3s Depends on text length
AI Detection 1-2s Fast for short text
Plagiarism 10-60s Async, requires polling

Instructions

Cache Score Results

import { LRUCache } from 'lru-cache';
import { createHash } from 'crypto';

const scoreCache = new LRUCache<string, any>({ max: 500, ttl: 3600000 });

async function cachedScore(text: string, token: string) {
  const key = createHash('sha256').update(text).digest('hex');
  const cached = scoreCache.get(key);
  if (cached) return cached;
  const score = await grammarlyClient.score(text);
  scoreCache.set(key, score);
  return score;
}

Parallel API Calls

// Score + AI detect in parallel (they're independent)
async function fullAudit(text: string, token: string) {
  const [score, ai] = await Promise.all([
    grammarlyClient.score(text),
    grammarlyClient.detectAI(text),
  ]);
  return { score, ai };
}

Resources

Next Steps

For cost optimization, see grammarly-cost-tuning.

信息
Category 编程开发
Name grammarly-performance-tuning
版本 v20260423
大小 1.77KB
更新时间 2026-04-28
语言