springload / draftjs_exporter

Convert Draft.js ContentState to HTML
https://www.draftail.org/blog/2018/03/13/rethinking-rich-text-pipelines-with-draft-js
MIT License
83 stars 21 forks source link

Small performance improvements per block #127

Closed thibaudcolas closed 4 years ago

thibaudcolas commented 4 years ago

Changes block rendering to:

Before:

$ BENCHMARK_RUNS=100 make benchmark
python benchmark.py
Exporting 792 ContentStates 100 times
         48263701 function calls (45467001 primitive calls) in 29.696 seconds

   Ordered by: cumulative time
   List reduced from 71 to 10 due to restriction <10>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    79200    0.918    0.000   29.696    0.000 html.py:55(render)
   565000    2.569    0.000   21.452    0.000 html.py:86(render_block)
   565000    1.274    0.000    8.137    0.000 wrapper_state.py:99(element_for)
    79200    0.045    0.000    6.486    0.000 dom.py:119(render)
1049100/79200    1.427    0.000    6.441    0.000 string.py:88(render)
934400/79200    0.686    0.000    6.377    0.000 string.py:79(render_children)
1358400/1242000    3.164    0.000    6.281    0.000 dom.py:37(create_element)
934400/79200    1.036    0.000    6.203    0.000 string.py:83(<listcomp>)
   764500    1.219    0.000    4.501    0.000 composite_decorators.py:56(render_decorators)
  1415200    0.842    0.000    3.021    0.000 composite_decorators.py:32(apply_decorators)

Measuring memory consumption
Filename: benchmark.py

Line #    Mem usage    Increment   Line Contents
================================================
   101  42.417969 MiB  42.417969 MiB   @profile(precision=6)
   102                             def memory_consumption_run():
   103  42.421875 MiB   0.003906 MiB       exporter = HTML(config)
   104
   105  42.535156 MiB   0.000000 MiB       for content_state in content_states:
   106  42.535156 MiB   0.050781 MiB           exporter.render(content_state)

After:

$ BENCHMARK_RUNS=100 make benchmark
python benchmark.py
Exporting 792 ContentStates 100 times
         41998201 function calls (39315301 primitive calls) in 22.440 seconds

   Ordered by: cumulative time
   List reduced from 68 to 10 due to restriction <10>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    79200    0.809    0.000   22.440    0.000 html.py:56(render)
   565000    1.691    0.000   14.683    0.000 html.py:87(render_block)
   565000    1.097    0.000    7.406    0.000 wrapper_state.py:99(element_for)
    79200    0.041    0.000    6.169    0.000 dom.py:124(render)
935300/79200    1.268    0.000    6.128    0.000 string.py:88(render)
934400/79200    0.630    0.000    6.072    0.000 string.py:79(render_children)
934400/79200    0.988    0.000    5.931    0.000 string.py:83(<listcomp>)
1244600/1128200    2.814    0.000    5.585    0.000 dom.py:37(create_element)
   565000    0.434    0.000    2.769    0.000 wrapper_state.py:116(parent_for)
  1113600    0.877    0.000    2.173    0.000 __init__.py:12(escape)

Measuring memory consumption
Filename: benchmark.py

Line #    Mem usage    Increment   Line Contents
================================================
   101  42.453125 MiB  42.453125 MiB   @profile(precision=6)
   102                             def memory_consumption_run():
   103  42.457031 MiB   0.003906 MiB       exporter = HTML(config)
   104
   105  42.546875 MiB   0.000000 MiB       for content_state in content_states:
   106  42.546875 MiB   0.042969 MiB           exporter.render(content_state)

Thanks for contributing to this project!