Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

ep: Compress EP requests (#48793)

Oleksiy Syvokonf0287d69e598
diff --git a/Cargo.lock b/Cargo.lock
index 95aa65c06ce..6c4addac4e4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5353,6 +5353,7 @@ dependencies = [
"zed_actions",
"zeta_prompt",
"zlog",
+ "zstd",
]
[[package]]
diff --git a/crates/edit_prediction/Cargo.toml b/crates/edit_prediction/Cargo.toml
index 767fd49a9f7..f1d0d308152 100644
--- a/crates/edit_prediction/Cargo.toml
+++ b/crates/edit_prediction/Cargo.toml
@@ -65,6 +65,7 @@ workspace.workspace = true
worktree.workspace = true
zed_actions.workspace = true
zeta_prompt.workspace = true
+zstd.workspace = true
[dev-dependencies]
clock = { workspace = true, features = ["test-support"] }
diff --git a/crates/edit_prediction/src/edit_prediction.rs b/crates/edit_prediction/src/edit_prediction.rs
index 1c2d756f279..f24a39353e6 100644
--- a/crates/edit_prediction/src/edit_prediction.rs
+++ b/crates/edit_prediction/src/edit_prediction.rs
@@ -1944,11 +1944,15 @@ impl EditPredictionStore {
let request = PredictEditsV3Request { input, trigger };
+ let json_bytes = serde_json::to_vec(&request)?;
+ let compressed = zstd::encode_all(&json_bytes[..], 3)?;
+
Self::send_api_request(
|builder| {
let req = builder
.uri(url.as_ref())
- .body(serde_json::to_string(&request)?.into());
+ .header("Content-Encoding", "zstd")
+ .body(compressed.clone().into());
Ok(req?)
},
client,
diff --git a/crates/edit_prediction/src/edit_prediction_tests.rs b/crates/edit_prediction/src/edit_prediction_tests.rs
index dad91c7fed9..19d2532de09 100644
--- a/crates/edit_prediction/src/edit_prediction_tests.rs
+++ b/crates/edit_prediction/src/edit_prediction_tests.rs
@@ -1380,7 +1380,8 @@ fn init_test_with_fake_client(
"/predict_edits/v3" => {
let mut buf = Vec::new();
body.read_to_end(&mut buf).await.ok();
- let req = serde_json::from_slice(&buf).unwrap();
+ let decompressed = zstd::decode_all(&buf[..]).unwrap();
+ let req = serde_json::from_slice(&decompressed).unwrap();
let (res_tx, res_rx) = oneshot::channel();
predict_req_tx.unbounded_send((req, res_tx)).unwrap();