Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/huge-parrots-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hardhat": patch
---

Improved performance of the network stack by removing a clone of the http request ([#8046](https://github.com/NomicFoundation/hardhat/issues/8046))
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type {
} from "../../../../types/providers.js";
import type { RequestHandler } from "../request-handlers/types.js";

import { deepClone } from "@nomicfoundation/hardhat-utils/lang";
import { AsyncMutex } from "@nomicfoundation/hardhat-utils/synchronization";

import { isJsonRpcResponse } from "../json-rpc.js";
Expand Down Expand Up @@ -61,21 +60,22 @@ export default async (): Promise<Partial<NetworkHooks>> => {
},
);

// We clone the request to avoid interfering with other hook handlers that
// might be using the original request.
let request = await deepClone(jsonRpcRequest);
// We previously cloned here, but the performance impact is significant.
// TODO: ensure the passed in request is not mutated by adapting the
// handlers being applied here. See https://github.com/NomicFoundation/hardhat/issues/8090
let updatedRequest = jsonRpcRequest;
Comment thread
kanej marked this conversation as resolved.

for (const handler of requestHandlers) {
const newRequestOrResponse = await handler.handle(request);
const newRequestOrResponse = await handler.handle(updatedRequest);

if (isJsonRpcResponse(newRequestOrResponse)) {
return newRequestOrResponse;
}

request = newRequestOrResponse;
updatedRequest = newRequestOrResponse;
}

return next(context, networkConnection, request);
return next(context, networkConnection, updatedRequest);
},

async closeConnection<ChainTypeT extends ChainType | string>(
Expand Down
Loading