From 077f3a79ef6ac8efa90085ac0942c89d0995069f Mon Sep 17 00:00:00 2001 From: David Frank Date: Thu, 21 Nov 2024 12:15:36 +0000 Subject: [PATCH] perf: Add inline hint to Ic0StableMemory methods These are small methods and hinting the compiler to inline them results in some nice performance gains. --- canbench_results.yml | 232 +++++++++++++++++++++---------------------- src/ic0_memory.rs | 4 + 2 files changed, 120 insertions(+), 116 deletions(-) diff --git a/canbench_results.yml b/canbench_results.yml index cd34e136..d80974e5 100644 --- a/canbench_results.yml +++ b/canbench_results.yml @@ -1,697 +1,697 @@ benches: btreemap_get_blob_128_1024: total: - instructions: 879302205 + instructions: 868028993 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_blob_128_1024_v2: total: - instructions: 986234201 + instructions: 970754065 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_blob_16_1024: total: - instructions: 315520793 + instructions: 304555831 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_blob_16_1024_v2: total: - instructions: 424439334 + instructions: 409386098 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_blob_256_1024: total: - instructions: 1410478508 + instructions: 1399133930 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_blob_256_1024_v2: total: - instructions: 1515420842 + instructions: 1499851078 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_blob_32_1024: total: - instructions: 359080553 + instructions: 347918329 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_blob_32_1024_v2: total: - instructions: 467643018 + instructions: 452317746 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_blob_4_1024: total: - instructions: 205936205 + instructions: 194406501 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_blob_4_1024_v2: total: - instructions: 304383660 + instructions: 289345080 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_blob_512_1024: total: - instructions: 2465612866 + instructions: 2454262332 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_blob_512_1024_v2: total: - instructions: 2571792093 + instructions: 2556213321 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_blob_64_1024: total: - instructions: 611173672 + instructions: 599847298 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_blob_64_1024_v2: total: - instructions: 727594763 + instructions: 712044951 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_blob_8_1024: total: - instructions: 242798942 + instructions: 231572100 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_blob_8_1024_v2: total: - instructions: 337855918 + instructions: 323197606 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_blob_8_u64: total: - instructions: 215475284 + instructions: 204171772 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_blob_8_u64_v2: total: - instructions: 326446044 + instructions: 311528236 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_u64_blob_8: total: - instructions: 198160835 + instructions: 186152093 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_u64_blob_8_v2: total: - instructions: 285194478 + instructions: 273254410 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_u64_u64: total: - instructions: 199393722 + instructions: 187408768 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_get_u64_u64_v2: total: - instructions: 291906450 + instructions: 279916538 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_insert_10mib_values: total: - instructions: 143394599 + instructions: 141252389 heap_increase: 0 stable_memory_increase: 32 scopes: {} btreemap_insert_blob_1024_128: total: - instructions: 5103816812 + instructions: 5083095809 heap_increase: 0 stable_memory_increase: 262 scopes: {} btreemap_insert_blob_1024_128_v2: total: - instructions: 5223665926 + instructions: 5196791890 heap_increase: 0 stable_memory_increase: 196 scopes: {} btreemap_insert_blob_1024_16: total: - instructions: 5060658098 + instructions: 5039894252 heap_increase: 0 stable_memory_increase: 241 scopes: {} btreemap_insert_blob_1024_16_v2: total: - instructions: 5181580835 + instructions: 5154652816 heap_increase: 0 stable_memory_increase: 181 scopes: {} btreemap_insert_blob_1024_256: total: - instructions: 5130558722 + instructions: 5109831287 heap_increase: 0 stable_memory_increase: 292 scopes: {} btreemap_insert_blob_1024_256_v2: total: - instructions: 5249596386 + instructions: 5222715261 heap_increase: 0 stable_memory_increase: 219 scopes: {} btreemap_insert_blob_1024_32: total: - instructions: 5069315515 + instructions: 5048498828 heap_increase: 0 stable_memory_increase: 239 scopes: {} btreemap_insert_blob_1024_32_v2: total: - instructions: 5192319151 + instructions: 5165315603 heap_increase: 0 stable_memory_increase: 180 scopes: {} btreemap_insert_blob_1024_4: total: - instructions: 4959470000 + instructions: 4938758192 heap_increase: 0 stable_memory_increase: 235 scopes: {} btreemap_insert_blob_1024_4_v2: total: - instructions: 5080388188 + instructions: 5053526974 heap_increase: 0 stable_memory_increase: 176 scopes: {} btreemap_insert_blob_1024_512: total: - instructions: 5252901073 + instructions: 5232116884 heap_increase: 0 stable_memory_increase: 348 scopes: {} btreemap_insert_blob_1024_512_v2: total: - instructions: 5373023593 + instructions: 5346066549 heap_increase: 0 stable_memory_increase: 261 scopes: {} btreemap_insert_blob_1024_64: total: - instructions: 5101699743 + instructions: 5080908184 heap_increase: 0 stable_memory_increase: 250 scopes: {} btreemap_insert_blob_1024_64_v2: total: - instructions: 5223434507 + instructions: 5196471697 heap_increase: 0 stable_memory_increase: 188 scopes: {} btreemap_insert_blob_1024_8: total: - instructions: 5043314359 + instructions: 5022590452 heap_increase: 0 stable_memory_increase: 237 scopes: {} btreemap_insert_blob_1024_8_v2: total: - instructions: 5163637162 + instructions: 5136760933 heap_increase: 0 stable_memory_increase: 178 scopes: {} btreemap_insert_blob_128_1024: total: - instructions: 1458078497 + instructions: 1437432650 heap_increase: 0 stable_memory_increase: 260 scopes: {} btreemap_insert_blob_128_1024_v2: total: - instructions: 1570349058 + instructions: 1543573613 heap_increase: 0 stable_memory_increase: 195 scopes: {} btreemap_insert_blob_16_1024: total: - instructions: 839064490 + instructions: 819015110 heap_increase: 0 stable_memory_increase: 215 scopes: {} btreemap_insert_blob_16_1024_v2: total: - instructions: 955395829 + instructions: 929386468 heap_increase: 0 stable_memory_increase: 161 scopes: {} btreemap_insert_blob_256_1024: total: - instructions: 2028664457 + instructions: 2007916344 heap_increase: 0 stable_memory_increase: 292 scopes: {} btreemap_insert_blob_256_1024_v2: total: - instructions: 2144398075 + instructions: 2117490329 heap_increase: 0 stable_memory_increase: 219 scopes: {} btreemap_insert_blob_32_1024: total: - instructions: 890749049 + instructions: 870306996 heap_increase: 0 stable_memory_increase: 230 scopes: {} btreemap_insert_blob_32_1024_v2: total: - instructions: 1007248566 + instructions: 980735900 heap_increase: 0 stable_memory_increase: 173 scopes: {} btreemap_insert_blob_4_1024: total: - instructions: 633932227 + instructions: 615105126 heap_increase: 0 stable_memory_increase: 123 scopes: {} btreemap_insert_blob_4_1024_v2: total: - instructions: 738087270 + instructions: 714364544 heap_increase: 0 stable_memory_increase: 92 scopes: {} btreemap_insert_blob_512_1024: total: - instructions: 3161385472 + instructions: 3140701710 heap_increase: 0 stable_memory_increase: 351 scopes: {} btreemap_insert_blob_512_1024_v2: total: - instructions: 3275260995 + instructions: 3248440359 heap_increase: 0 stable_memory_increase: 263 scopes: {} btreemap_insert_blob_64_1024: total: - instructions: 1157359426 + instructions: 1136783783 heap_increase: 0 stable_memory_increase: 245 scopes: {} btreemap_insert_blob_64_1024_v2: total: - instructions: 1281618754 + instructions: 1254935822 heap_increase: 0 stable_memory_increase: 183 scopes: {} btreemap_insert_blob_8_1024: total: - instructions: 758180070 + instructions: 737978721 heap_increase: 0 stable_memory_increase: 183 scopes: {} btreemap_insert_blob_8_1024_v2: total: - instructions: 866287942 + instructions: 840828948 heap_increase: 0 stable_memory_increase: 138 scopes: {} btreemap_insert_blob_8_u64: total: - instructions: 353807315 + instructions: 333681568 heap_increase: 0 stable_memory_increase: 6 scopes: {} btreemap_insert_blob_8_u64_v2: total: - instructions: 473686702 + instructions: 448187595 heap_increase: 0 stable_memory_increase: 4 scopes: {} btreemap_insert_u64_blob_8: total: - instructions: 364631146 + instructions: 343283004 heap_increase: 0 stable_memory_increase: 7 scopes: {} btreemap_insert_u64_blob_8_v2: total: - instructions: 450222711 + instructions: 429045170 heap_increase: 0 stable_memory_increase: 5 scopes: {} btreemap_insert_u64_u64: total: - instructions: 374696730 + instructions: 353426417 heap_increase: 0 stable_memory_increase: 7 scopes: {} btreemap_insert_u64_u64_v2: total: - instructions: 462904999 + instructions: 441738753 heap_increase: 0 stable_memory_increase: 6 scopes: {} btreemap_iter_10mib_values: total: - instructions: 17116720 + instructions: 17054815 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_iter_count_10mib_values: total: - instructions: 527176 + instructions: 492818 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_iter_count_small_values: total: - instructions: 10158843 + instructions: 9854951 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_iter_rev_10mib_values: total: - instructions: 17114625 + instructions: 17052720 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_iter_rev_small_values: total: - instructions: 14524294 + instructions: 13980402 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_iter_small_values: total: - instructions: 14527493 + instructions: 13983601 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_keys_10mib_values: total: - instructions: 516764 + instructions: 482392 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_keys_rev_10mib_values: total: - instructions: 519117 + instructions: 484745 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_keys_rev_small_values: total: - instructions: 10530635 + instructions: 10226743 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_keys_small_values: total: - instructions: 10294798 + instructions: 9990906 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_read_every_third_value_from_range: total: - instructions: 113084618 + instructions: 112238714 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_read_keys_from_range: total: - instructions: 113084618 + instructions: 112238714 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_128_1024: total: - instructions: 1814329611 + instructions: 1783414773 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_128_1024_v2: total: - instructions: 1982178501 + instructions: 1942678397 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_16_1024: total: - instructions: 1046555128 + instructions: 1017479433 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_16_1024_v2: total: - instructions: 1207409244 + instructions: 1170176089 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_256_1024: total: - instructions: 2484528504 + instructions: 2454002394 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_256_1024_v2: total: - instructions: 2645421668 + instructions: 2606407435 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_32_1024: total: - instructions: 1125110448 + instructions: 1095183445 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_32_1024_v2: total: - instructions: 1290917923 + instructions: 1252648744 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_4_1024: total: - instructions: 639953529 + instructions: 617902738 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_4_1024_v2: total: - instructions: 763706218 + instructions: 735874430 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_512_1024: total: - instructions: 3880456183 + instructions: 3849259424 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_512_1024_v2: total: - instructions: 4043734433 + instructions: 4003887427 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_64_1024: total: - instructions: 1458217613 + instructions: 1427599410 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_64_1024_v2: total: - instructions: 1631937179 + instructions: 1592814332 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_8_1024: total: - instructions: 843328385 + instructions: 816476142 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_8_1024_v2: total: - instructions: 986540048 + instructions: 952832423 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_8_u64: total: - instructions: 465951671 + instructions: 438199023 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_8_u64_v2: total: - instructions: 626297968 + instructions: 591309106 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_u64_blob_8: total: - instructions: 516865037 + instructions: 485820315 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_u64_blob_8_v2: total: - instructions: 637827582 + instructions: 606724491 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_u64_u64: total: - instructions: 537895420 + instructions: 506491112 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_u64_u64_v2: total: - instructions: 668544917 + instructions: 637006929 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_values_10mib_values: total: - instructions: 17140501 + instructions: 17078596 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_values_rev_10mib_values: total: - instructions: 17139292 + instructions: 17077387 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_values_rev_small_values: total: - instructions: 15756258 + instructions: 15212366 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_values_small_values: total: - instructions: 15715453 + instructions: 15171561 heap_increase: 0 stable_memory_increase: 0 scopes: {} memory_manager_baseline: total: - instructions: 1176577052 + instructions: 1176576907 heap_increase: 0 stable_memory_increase: 8000 scopes: {} memory_manager_grow: total: - instructions: 351687872 + instructions: 349639872 heap_increase: 2 stable_memory_increase: 32000 scopes: {} memory_manager_overhead: total: - instructions: 1182143127 + instructions: 1182119117 heap_increase: 0 stable_memory_increase: 8320 scopes: {} vec_get_blob_128: total: - instructions: 21620835 + instructions: 21384965 heap_increase: 0 stable_memory_increase: 0 scopes: {} vec_get_blob_16: total: - instructions: 9954082 + instructions: 9821962 heap_increase: 0 stable_memory_increase: 0 scopes: {} vec_get_blob_32: total: - instructions: 10864853 + instructions: 10694461 heap_increase: 0 stable_memory_increase: 0 scopes: {} vec_get_blob_4: total: - instructions: 5894588 + instructions: 5814638 heap_increase: 0 stable_memory_increase: 0 scopes: {} vec_get_blob_64: total: - instructions: 15712671 + instructions: 15512039 heap_increase: 0 stable_memory_increase: 0 scopes: {} vec_get_blob_8: total: - instructions: 7151499 + instructions: 6947467 heap_increase: 0 stable_memory_increase: 0 scopes: {} vec_get_u64: total: - instructions: 6430307 + instructions: 6220307 heap_increase: 0 stable_memory_increase: 0 scopes: {} vec_insert_blob_128: total: - instructions: 4901596 + instructions: 4271444 heap_increase: 0 stable_memory_increase: 19 scopes: {} vec_insert_blob_16: total: - instructions: 4066246 + instructions: 3436230 heap_increase: 0 stable_memory_increase: 2 scopes: {} vec_insert_blob_32: total: - instructions: 4185513 + instructions: 3555473 heap_increase: 0 stable_memory_increase: 5 scopes: {} vec_insert_blob_4: total: - instructions: 3977469 + instructions: 3347469 heap_increase: 0 stable_memory_increase: 0 scopes: {} vec_insert_blob_64: total: - instructions: 4425886 + instructions: 3795814 heap_increase: 0 stable_memory_increase: 9 scopes: {} vec_insert_blob_8: total: - instructions: 4006899 + instructions: 3376891 heap_increase: 0 stable_memory_increase: 1 scopes: {} vec_insert_u64: total: - instructions: 6109442 + instructions: 5649434 heap_increase: 0 stable_memory_increase: 1 scopes: {} diff --git a/src/ic0_memory.rs b/src/ic0_memory.rs index db1322c0..00078dd0 100644 --- a/src/ic0_memory.rs +++ b/src/ic0_memory.rs @@ -12,21 +12,25 @@ extern "C" { pub struct Ic0StableMemory; impl Memory for Ic0StableMemory { + #[inline] fn size(&self) -> u64 { // SAFETY: This is safe because of the ic0 api guarantees. unsafe { stable64_size() } } + #[inline] fn grow(&self, pages: u64) -> i64 { // SAFETY: This is safe because of the ic0 api guarantees. unsafe { stable64_grow(pages) } } + #[inline] fn read(&self, offset: u64, dst: &mut [u8]) { // SAFETY: This is safe because of the ic0 api guarantees. unsafe { stable64_read(dst.as_ptr() as u64, offset, dst.len() as u64) } } + #[inline] fn write(&self, offset: u64, src: &[u8]) { // SAFETY: This is safe because of the ic0 api guarantees. unsafe { stable64_write(offset, src.as_ptr() as u64, src.len() as u64) }