Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Summary of a skill for memory-safe streaming exports of large Excel, CSV, JSON and PDF files: OOM, temp files, blocking, formula injection.
77% 95%+18 ptsof test cases passed
Passed 21 of 22 test cases with the skill, and 17 of 22 without it.
我们系统里的订单导出功能最近频繁报 OOM 错误。后台代码是用 Java 的 XSSFWorkbook 一次性加载几万条数据库记录并构建 Excel 文件的,前端直接通过 HTTP 请求等待下载。请帮我审查代码逻辑并提供改写方案,要求调整为内存安全的导出方式,处理好临时资源回收,并按照后台异步任务机制重新设计接口交互。
Recommends replacing XSSFWorkbook with SXSSF for streaming Excel generation.
3 of 3 safety checks passed
当一次性 in-memory 构建数据超过 1 万行 / 10 MB,或数据量由用户筛选决定且无法预估上限时,必须切换为流式 / 分页 API。 否则常见后果:OOM、Full GC 风暴、临时文件残留、HTTP 超时。
适用:
SXSSFWorkbook、XSSFWorkbook、EasyExcel、openpyxl、excelize、ExcelJS、PDFKit、ReportLab、JsonGenerator 等导出库不适用:
Writer / Report / Download 命名但不涉及大数据导出| 数据量级 | 推荐模式 | 备注 |
|---|---|---|
| ≤ 1 万行 / ≤ 5 MB | 内存构建 OK | XSSFWorkbook / pandas / 普通 JSON 序列化 |
| 1 万 ~ 10 万行 | 强烈建议流式 | 单机够用,但有 OOM 风险 |
| > 10 万行 / > 50 MB | 必须流式 + 异步 | 内存模型会爆 |
| 数据量未知(用户驱动) | 必须流式 + 上限保护 | 永远按最坏情况设计 |
核心判断:能不能预估上限?预估超过 1 万行就上流式。
Published skills whose descriptions closely match this one, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.