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

Optional source map generation #6894

Merged
merged 1 commit into from
Aug 26, 2023
Merged

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Aug 26, 2023

Summary

This PR makes the formatter's source map generation optional.

Source mapping informatin is useful to implement range formatting or to move the cursor to the same position in the formatted document. But it comes at the cost of a much larger Document (one each at the start and end of every node) and a large source map created by writting source markers in the Printer (one marker at the start and end of every text).
This PR makes the source map generation option so that we don't pay the overhead when it isn't needed.

Test Plan

cargo test

Performance improves locally by about 16%

formatter/numpy/globals.py
                        time:   [36.860 µs 36.908 µs 36.971 µs]
                        thrpt:  [79.811 MiB/s 79.946 MiB/s 80.050 MiB/s]
                 change:
                        time:   [-16.602% -16.431% -16.245%] (p = 0.00 < 0.05)
                        thrpt:  [+19.396% +19.662% +19.907%]
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  4 (4.00%) high mild
  2 (2.00%) high severe
formatter/pydantic/types.py
                        time:   [771.54 µs 773.43 µs 775.26 µs]
                        thrpt:  [32.896 MiB/s 32.974 MiB/s 33.055 MiB/s]
                 change:
                        time:   [-17.740% -17.519% -17.303%] (p = 0.00 < 0.05)
                        thrpt:  [+20.923% +21.240% +21.566%]
                        Performance has improved.
formatter/numpy/ctypeslib.py
                        time:   [408.12 µs 408.48 µs 408.90 µs]
                        thrpt:  [40.722 MiB/s 40.763 MiB/s 40.799 MiB/s]
                 change:
                        time:   [-16.845% -15.595% -14.821%] (p = 0.00 < 0.05)
                        thrpt:  [+17.400% +18.476% +20.257%]
                        Performance has improved.
Found 7 outliers among 100 measurements (7.00%)
  3 (3.00%) high mild
  4 (4.00%) high severe
formatter/large/dataset.py
                        time:   [2.1040 ms 2.1059 ms 2.1084 ms]
                        thrpt:  [19.295 MiB/s 19.318 MiB/s 19.336 MiB/s]
                 change:
                        time:   [-14.956% -14.812% -14.648%] (p = 0.00 < 0.05)
                        thrpt:  [+17.162% +17.387% +17.586%]
                        Performance has improved.
Found 11 outliers among 100 measurements (11.00%)
  6 (6.00%) high mild
  5 (5.00%) high severe

@MichaReiser
Copy link
Member Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@MichaReiser MichaReiser changed the title Make source map generation configurable Make source map generation optional Aug 26, 2023
@MichaReiser MichaReiser changed the title Make source map generation optional Optional source map generation Aug 26, 2023
@MichaReiser MichaReiser added performance Potential performance improvement formatter Related to the formatter labels Aug 26, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 26, 2023

PR Check Results

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.16      4.5±0.02ms     9.1 MB/sec    1.00      3.8±0.02ms    10.6 MB/sec
formatter/numpy/ctypeslib.py               1.12    882.8±2.44µs    18.9 MB/sec    1.00    789.3±2.16µs    21.1 MB/sec
formatter/numpy/globals.py                 1.10     82.7±0.35µs    35.7 MB/sec    1.00     75.5±0.37µs    39.1 MB/sec
formatter/pydantic/types.py                1.17   1680.5±9.86µs    15.2 MB/sec    1.00   1437.5±3.35µs    17.7 MB/sec
linter/all-rules/large/dataset.py          1.00     10.1±0.05ms     4.0 MB/sec    1.00     10.1±0.06ms     4.0 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      2.7±0.00ms     6.1 MB/sec    1.00      2.7±0.00ms     6.1 MB/sec
linter/all-rules/numpy/globals.py          1.01    381.0±0.65µs     7.7 MB/sec    1.00    378.9±1.44µs     7.8 MB/sec
linter/all-rules/pydantic/types.py         1.01      5.3±0.09ms     4.8 MB/sec    1.00      5.2±0.02ms     4.9 MB/sec
linter/default-rules/large/dataset.py      1.00      5.3±0.03ms     7.6 MB/sec    1.02      5.4±0.05ms     7.5 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00   1180.2±3.65µs    14.1 MB/sec    1.01   1190.1±4.07µs    14.0 MB/sec
linter/default-rules/numpy/globals.py      1.00    136.7±0.23µs    21.6 MB/sec    1.01    138.7±0.23µs    21.3 MB/sec
linter/default-rules/pydantic/types.py     1.00      2.4±0.02ms    10.6 MB/sec    1.01      2.4±0.01ms    10.5 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.22      5.2±0.07ms     7.8 MB/sec    1.00      4.3±0.06ms     9.5 MB/sec
formatter/numpy/ctypeslib.py               1.18  1010.4±25.81µs    16.5 MB/sec    1.00   854.0±12.90µs    19.5 MB/sec
formatter/numpy/globals.py                 1.16     94.1±1.57µs    31.3 MB/sec    1.00     80.8±1.95µs    36.5 MB/sec
formatter/pydantic/types.py                1.24  1954.0±25.11µs    13.1 MB/sec    1.00  1578.0±21.39µs    16.2 MB/sec
linter/all-rules/large/dataset.py          1.01     12.6±0.20ms     3.2 MB/sec    1.00     12.4±0.21ms     3.3 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.01      3.4±0.06ms     4.8 MB/sec    1.00      3.4±0.04ms     4.9 MB/sec
linter/all-rules/numpy/globals.py          1.01    422.3±5.60µs     7.0 MB/sec    1.00    418.7±5.23µs     7.0 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.6±0.14ms     3.9 MB/sec    1.00      6.6±0.11ms     3.9 MB/sec
linter/default-rules/large/dataset.py      1.00      6.9±0.08ms     5.9 MB/sec    1.00      6.9±0.08ms     5.9 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00  1471.5±19.77µs    11.3 MB/sec    1.00  1474.0±15.48µs    11.3 MB/sec
linter/default-rules/numpy/globals.py      1.01    170.8±4.53µs    17.3 MB/sec    1.00    169.4±3.10µs    17.4 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.1±0.04ms     8.3 MB/sec    1.00      3.1±0.04ms     8.3 MB/sec

@MichaReiser MichaReiser force-pushed the configurable-source-map-generation branch from e44184d to 63c9c92 Compare August 26, 2023 12:55
@MichaReiser MichaReiser force-pushed the configurable-source-map-generation branch from 63c9c92 to 3053c1b Compare August 26, 2023 14:50
@codspeed-hq
Copy link

codspeed-hq bot commented Aug 26, 2023

CodSpeed Performance Report

Merging #6894 will improve performances by 19.02%

⚠️ No base runs were found

Falling back to comparing configurable-source-map-generation (3053c1b) with main (ed1b412)

Summary

🔥 4 improvements
✅ 12 untouched benchmarks

Benchmarks breakdown

Benchmark main configurable-source-map-generation Change
🔥 formatter[numpy/ctypeslib.py] 13.9 ms 12 ms +16.19%
🔥 formatter[pydantic/types.py] 26.3 ms 22.1 ms +19.02%
🔥 formatter[numpy/globals.py] 1.4 ms 1.3 ms +10.53%
🔥 formatter[large/dataset.py] 72.7 ms 61.7 ms +17.77%

@MichaReiser MichaReiser merged commit eae59cf into main Aug 26, 2023
16 checks passed
@MichaReiser MichaReiser deleted the configurable-source-map-generation branch August 26, 2023 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter performance Potential performance improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants