+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

refactor: use std::sync::Mutex instead of parking_lot::Mutex #3095

Merged
merged 2 commits into from
Aug 23, 2022

Conversation

IWANABETHATGUY
Copy link
Contributor

Summary

  1. Part of ☂️ Tracking issues or potential improvement we could make after upgrades to the Rust toolchain #3054
  2. With the standard library Mutex and RwLock being const-constructible it's now possible to use these in the DiffReport of the Prettier test suite

Test Plan

  1. Passing CI

Copy link
Contributor

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Another change that should be part of this PR is removing lazy_static around the definition of METRICS.

Now that Mutex can be defined as const, the usage of lazy_static is not needed anymore.

@IWANABETHATGUY
Copy link
Contributor Author

Seems not, rustc doesn't allow us to create a const Mutex that inner value can't create in compile time.
rustc emit errors below:

cannot call non-const fn `HashMap::<CallsiteKey, Mutex<CallsiteEntry>>::new` in constants
calls in constants are limited to constant functions, tuple structs and tuple variants

@xunilrj
Copy link
Contributor

xunilrj commented Aug 23, 2022

!bench_analyzer

@xunilrj
Copy link
Contributor

xunilrj commented Aug 23, 2022

!bench_formatter

@github-actions
Copy link

Analyzer Benchmark Results

group                     main                                   pr
-----                     ----                                   --
analyzer/css.js           1.00      2.2±0.00ms     5.2 MB/sec    1.00      2.2±0.00ms     5.3 MB/sec
analyzer/index.js         1.00      6.0±0.03ms     5.4 MB/sec    1.01      6.0±0.07ms     5.4 MB/sec
analyzer/lint.ts          1.00      3.2±0.01ms    13.1 MB/sec    1.00      3.2±0.01ms    13.1 MB/sec
analyzer/parser.ts        1.01      7.4±0.15ms     6.6 MB/sec    1.00      7.4±0.03ms     6.6 MB/sec
analyzer/router.ts        1.01      5.2±0.08ms    11.8 MB/sec    1.00      5.2±0.04ms    11.9 MB/sec
analyzer/statement.ts     1.01      7.0±0.04ms     5.1 MB/sec    1.00      7.0±0.02ms     5.1 MB/sec
analyzer/typescript.ts    1.00     10.5±0.10ms     5.2 MB/sec    1.01     10.6±0.10ms     5.1 MB/sec

@ematipico
Copy link
Contributor

Seems not, rustc doesn't allow us to create a const Mutex that inner value can't create in compile time. rustc emit errors below:

cannot call non-const fn `HashMap::<CallsiteKey, Mutex<CallsiteEntry>>::new` in constants
calls in constants are limited to constant functions, tuple structs and tuple variants

Really difficult to give feedback without seeing the code, but removing only lazy_static is not correct, we have to do some refactor.

@IWANABETHATGUY
Copy link
Contributor Author

pile time. rustc emit errors below:

image

@IWANABETHATGUY
Copy link
Contributor Author

The only way I know to create a hashmap in compile time is phf

@MichaReiser
Copy link
Contributor

Seems not, rustc doesn't allow us to create a const Mutex that inner value can't create in compile time. rustc emit errors below:

cannot call non-const fn `HashMap::<CallsiteKey, Mutex<CallsiteEntry>>::new` in constants
calls in constants are limited to constant functions, tuple structs and tuple variants

Really difficult to give feedback without seeing the code, but removing only lazy_static is not correct, we have to do some refactor.

The problem is that RwLock stores a HashMap and HashMap::new is not const. So you can write RwLock::new(...) but there's no way to create the map.

@github-actions
Copy link

Formatter Benchmark Results

group                                    main                                   pr
-----                                    ----                                   --
formatter/checker.ts                     1.06   512.2±12.60ms     5.1 MB/sec    1.00   484.9±10.47ms     5.4 MB/sec
formatter/compiler.js                    1.01    317.5±8.22ms     3.3 MB/sec    1.00    313.8±7.57ms     3.3 MB/sec
formatter/d3.min.js                      1.01    258.8±9.30ms  1037.2 KB/sec    1.00    255.8±7.42ms  1049.4 KB/sec
formatter/dojo.js                        1.02     16.6±0.74ms     4.1 MB/sec    1.00     16.3±0.59ms     4.2 MB/sec
formatter/ios.d.ts                       1.03   320.9±11.40ms     5.8 MB/sec    1.00    310.7±7.25ms     6.0 MB/sec
formatter/jquery.min.js                  1.00     69.8±2.31ms  1212.2 KB/sec    1.00     69.6±3.64ms  1216.0 KB/sec
formatter/math.js                        1.02   542.7±12.78ms  1221.9 KB/sec    1.00   531.0±17.10ms  1248.6 KB/sec
formatter/parser.ts                      1.02     10.8±0.34ms     4.5 MB/sec    1.00     10.6±0.31ms     4.6 MB/sec
formatter/pixi.min.js                    1.02   305.2±17.96ms  1472.3 KB/sec    1.00    298.1±9.10ms  1507.4 KB/sec
formatter/react-dom.production.min.js    1.00     84.9±3.38ms  1387.8 KB/sec    1.00     84.9±5.15ms  1388.1 KB/sec
formatter/react.production.min.js        1.01      4.1±0.16ms  1553.0 KB/sec    1.00      4.0±0.13ms  1570.6 KB/sec
formatter/router.ts                      1.01      8.3±0.21ms     7.4 MB/sec    1.00      8.2±0.33ms     7.5 MB/sec
formatter/tex-chtml-full.js              1.02   691.1±12.60ms  1350.3 KB/sec    1.00   680.7±23.69ms  1370.9 KB/sec
formatter/three.min.js                   1.01   334.3±10.94ms  1798.2 KB/sec    1.00    331.7±9.14ms  1812.6 KB/sec
formatter/typescript.js                  1.02       2.1±0.02s     4.6 MB/sec    1.00       2.0±0.03s     4.7 MB/sec
formatter/vue.global.prod.js             1.01    113.9±4.38ms  1083.0 KB/sec    1.00    113.1±6.04ms  1090.7 KB/sec

@MichaReiser MichaReiser merged commit e9eb7a0 into rome:main Aug 23, 2022
@IWANABETHATGUY IWANABETHATGUY deleted the refactor/mutex branch August 23, 2022 11:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载