From 7873084a06a2c8dd811bcd94801e33ea2c9eef7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Gaspard?= Date: Fri, 23 Sep 2022 13:43:31 +0200 Subject: [PATCH] remove unneeded clones within to_vec calls Performance behavior: In a test case extracted from nearcore-private#6, performance: - improves by 5-10% on rayon - improves by 5-6% on non-rayon In a test case extracted from nearcore-private#7, performance stays roughly the same. --- lib/compiler-singlepass/src/codegen_x64.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/compiler-singlepass/src/codegen_x64.rs b/lib/compiler-singlepass/src/codegen_x64.rs index aa3fe6b0c..c66ca3b08 100644 --- a/lib/compiler-singlepass/src/codegen_x64.rs +++ b/lib/compiler-singlepass/src/codegen_x64.rs @@ -8423,7 +8423,8 @@ impl<'a> FuncGen<'a> { let body_len = self.assembler.get_offset().0; let instructions_address_map = self.instructions_address_map; let address_map = get_function_address_map(instructions_address_map, data, body_len); - let body = self.assembler.finalize().unwrap().to_vec(); + let mut body = self.assembler.finalize().unwrap(); + body.shrink_to_fit(); CompiledFunction { body: FunctionBody { @@ -8605,8 +8606,10 @@ pub(crate) fn gen_std_trampoline( a.emit_ret(); + let mut body = a.finalize().unwrap(); + body.shrink_to_fit(); FunctionBody { - body: a.finalize().unwrap().to_vec(), + body, unwind_info: None, } } @@ -8727,8 +8730,10 @@ pub(crate) fn gen_std_dynamic_import_trampoline( // Return. a.emit_ret(); + let mut body = a.finalize().unwrap(); + body.shrink_to_fit(); FunctionBody { - body: a.finalize().unwrap().to_vec(), + body, unwind_info: None, } } @@ -8889,7 +8894,9 @@ pub(crate) fn gen_import_call_trampoline( } a.emit_host_redirection(GPR::RAX); - let section_body = SectionBody::new_with_vec(a.finalize().unwrap().to_vec()); + let mut contents = a.finalize().unwrap(); + contents.shrink_to_fit(); + let section_body = SectionBody::new_with_vec(contents); CustomSection { protection: CustomSectionProtection::ReadExecute,