Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary allocation/copy from the string serialization implementation #566

Merged
merged 1 commit into from
Aug 9, 2024

Conversation

frankdavid
Copy link
Contributor

@frankdavid frankdavid commented Aug 9, 2024

Avoid creating an intermediate vector when serializing texts.

Affected benchmarks:

Benchmark: text
  total:
    instructions: 38.30 M (improved by 17.97%)
    heap_increase: 99 pages (no change)
    stable_memory_increase: 0 pages (no change)

  1. Encoding (scope):
    instructions: 20.46 M (improved by 29.08%)
    heap_increase: 66 pages (improved by 33.33%)
    stable_memory_increase: 0 pages (no change)

  2. Decoding (scope):
    instructions: 17.84 M (0.00%) (change within noise threshold)
    heap_increase: 33 pages (regressed from 0)
    stable_memory_increase: 0 pages (no change)
Benchmark: btreemap
  total:
    instructions: 19.75 B (improved by 2.44%)
    heap_increase: 1179 pages (1.29%) (change within noise threshold)
    stable_memory_increase: 0 pages (no change)

  1. Encoding (scope):
    instructions: 4.02 B (improved by 10.70%)
    heap_increase: 159 pages (improved by 38.13%)
    stable_memory_increase: 0 pages (no change)

  2. Decoding (scope):
    instructions: 15.72 B (-0.08%) (change within noise threshold)
    heap_increase: 1020 pages (regressed by 12.46%)
    stable_memory_increase: 0 pages (no change)

My assumption is that the heap_increase regression in the decoding phase is due to the fact that heap is not reclaimed after encoding. Since encoding uses less heap after this change, the heap increase for the decoding phase is now higher.

Copy link

github-actions bot commented Aug 9, 2024

Name Max Mem (Kb) Encode Decode
blob 4_224 20_459_319 ($\textcolor{green}{-0.00\%}$) 12_083_390
btreemap 75_456 ($\textcolor{red}{1.29\%}$) 4_022_699_921 ($\textcolor{green}{-10.70\%}$) 15_709_219_501 ($\textcolor{green}{-0.08\%}$)
nns 192 2_257_486 ($\textcolor{green}{-0.96\%}$) 12_617_469 ($\textcolor{green}{-0.14\%}$)
nns_list_proposal 1_792 7_041_444 ($\textcolor{green}{-0.35\%}$) 187_610_779 ($\textcolor{red}{0.01\%}$)
option_list 576 7_141_454 ($\textcolor{red}{0.01\%}$) 32_450_234 ($\textcolor{red}{0.28\%}$)
text 6_336 20_455_442 ($\textcolor{green}{-29.08\%}$) 17_839_372 ($\textcolor{red}{0.00\%}$)
variant_list 128 7_142_657 ($\textcolor{red}{0.00\%}$) 24_608_159
vec_int16 16_704 168_582_443 ($\textcolor{green}{-0.00\%}$) 1_073_771_349
  • Parser cost: 18_786_815 ($\textcolor{red}{0.00\%}$)
  • Extra args: 3_254_228
Click to see raw report

---------------------------------------------------

Benchmark: blob
  total:
    instructions: 32.54 M (-0.00%) (change within noise threshold)
    heap_increase: 66 pages (no change)
    stable_memory_increase: 0 pages (no change)

  1. Encoding (scope):
    instructions: 20.46 M (-0.00%) (change within noise threshold)
    heap_increase: 66 pages (no change)
    stable_memory_increase: 0 pages (no change)

  2. Decoding (scope):
    instructions: 12.08 M (no change)
    heap_increase: 0 pages (no change)
    stable_memory_increase: 0 pages (no change)

---------------------------------------------------

Benchmark: text
  total:
    instructions: 38.30 M (improved by 17.97%)
    heap_increase: 99 pages (no change)
    stable_memory_increase: 0 pages (no change)

  1. Encoding (scope):
    instructions: 20.46 M (improved by 29.08%)
    heap_increase: 66 pages (improved by 33.33%)
    stable_memory_increase: 0 pages (no change)

  2. Decoding (scope):
    instructions: 17.84 M (0.00%) (change within noise threshold)
    heap_increase: 33 pages (regressed from 0)
    stable_memory_increase: 0 pages (no change)

---------------------------------------------------

Benchmark: vec_int16
  total:
    instructions: 1.24 B (-0.00%) (change within noise threshold)
    heap_increase: 261 pages (no change)
    stable_memory_increase: 0 pages (no change)

  1. Encoding (scope):
    instructions: 168.58 M (-0.00%) (change within noise threshold)
    heap_increase: 261 pages (no change)
    stable_memory_increase: 0 pages (no change)

  2. Decoding (scope):
    instructions: 1.07 B (no change)
    heap_increase: 0 pages (no change)
    stable_memory_increase: 0 pages (no change)

---------------------------------------------------

Benchmark: btreemap
  total:
    instructions: 19.73 B (improved by 2.45%)
    heap_increase: 1179 pages (1.29%) (change within noise threshold)
    stable_memory_increase: 0 pages (no change)

  1. Encoding (scope):
    instructions: 4.02 B (improved by 10.70%)
    heap_increase: 159 pages (improved by 38.13%)
    stable_memory_increase: 0 pages (no change)

  2. Decoding (scope):
    instructions: 15.71 B (-0.08%) (change within noise threshold)
    heap_increase: 1020 pages (regressed by 12.46%)
    stable_memory_increase: 0 pages (no change)

---------------------------------------------------

Benchmark: option_list
  total:
    instructions: 39.59 M (0.23%) (change within noise threshold)
    heap_increase: 9 pages (no change)
    stable_memory_increase: 0 pages (no change)

  1. Encoding (scope):
    instructions: 7.14 M (0.01%) (change within noise threshold)
    heap_increase: 0 pages (no change)
    stable_memory_increase: 0 pages (no change)

  2. Decoding (scope):
    instructions: 32.45 M (0.28%) (change within noise threshold)
    heap_increase: 9 pages (no change)
    stable_memory_increase: 0 pages (no change)

---------------------------------------------------

Benchmark: variant_list
  total:
    instructions: 31.75 M (0.00%) (change within noise threshold)
    heap_increase: 2 pages (no change)
    stable_memory_increase: 0 pages (no change)

  1. Encoding (scope):
    instructions: 7.14 M (0.00%) (change within noise threshold)
    heap_increase: 0 pages (no change)
    stable_memory_increase: 0 pages (no change)

  2. Decoding (scope):
    instructions: 24.61 M (no change)
    heap_increase: 2 pages (no change)
    stable_memory_increase: 0 pages (no change)

---------------------------------------------------

Benchmark: nns
  total:
    instructions: 34.50 M (-0.11%) (change within noise threshold)
    heap_increase: 3 pages (no change)
    stable_memory_increase: 0 pages (no change)

  0. Parsing (scope):
    instructions: 18.79 M (0.00%) (change within noise threshold)
    heap_increase: 2 pages (no change)
    stable_memory_increase: 0 pages (no change)

  1. Encoding (scope):
    instructions: 2.26 M (-0.96%) (change within noise threshold)
    heap_increase: 0 pages (no change)
    stable_memory_increase: 0 pages (no change)

  2. Decoding (scope):
    instructions: 12.62 M (-0.14%) (change within noise threshold)
    heap_increase: 1 pages (no change)
    stable_memory_increase: 0 pages (no change)

---------------------------------------------------

Benchmark: nns_list_proposal
  total:
    instructions: 194.65 M (-0.01%) (change within noise threshold)
    heap_increase: 28 pages (no change)
    stable_memory_increase: 0 pages (no change)

  1. Encoding (scope):
    instructions: 7.04 M (-0.35%) (change within noise threshold)
    heap_increase: 3 pages (no change)
    stable_memory_increase: 0 pages (no change)

  2. Decoding (scope):
    instructions: 187.61 M (0.01%) (change within noise threshold)
    heap_increase: 25 pages (no change)
    stable_memory_increase: 0 pages (no change)

---------------------------------------------------

Benchmark: extra_args
  total:
    instructions: 3.25 M (no change)
    heap_increase: 0 pages (no change)
    stable_memory_increase: 0 pages (no change)

---------------------------------------------------
Successfully persisted results to canbench_results.yml

Copy link
Contributor

@chenyan-dfinity chenyan-dfinity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@frankdavid frankdavid merged commit bba0b53 into master Aug 9, 2024
6 checks passed
@frankdavid frankdavid deleted the frankdavid/optimize-copy branch August 9, 2024 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants