3D 产物读取按声明长度预分配缓冲
- server-rs/crates/api-server/src/tripo3d/artifacts.rs:read_artifact 用 Vec::with_capacity 按 provider 声明的 content_length 预分配(并封顶到 512 MiB 上限,防止谎报长度撑爆内存),避免几百 MB 产物逐块 extend 反复搬移 验证:cargo check -p api-server(--locked)
This commit is contained in:
@@ -25,7 +25,13 @@ pub(crate) async fn read_artifact(
|
||||
mut artifact: TripoDownloadedArtifact,
|
||||
) -> Result<DownloadedArtifact, AppError> {
|
||||
let content_type = artifact.content_type.clone().unwrap_or_default();
|
||||
let mut bytes = Vec::new();
|
||||
// 按声明长度预分配(封顶到单产物上限,防止 provider 谎报长度撑爆内存):
|
||||
// 几百 MB 的模型逐块 append 会反复搬移,预分配把峰值与拷贝都压下来。
|
||||
let claimed_bytes = artifact
|
||||
.content_length
|
||||
.unwrap_or(0)
|
||||
.min(MODEL3D_MAX_ARTIFACT_BYTES) as usize;
|
||||
let mut bytes = Vec::with_capacity(claimed_bytes);
|
||||
while let Some(chunk) = artifact.next_chunk().await.map_err(map_provider_error)? {
|
||||
let next_len = bytes.len() as u64 + chunk.len() as u64;
|
||||
if next_len > MODEL3D_MAX_ARTIFACT_BYTES {
|
||||
|
||||
Reference in New Issue
Block a user