swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
31.3k stars 1.23k forks source link

Redesign comment system #1952

Open kdy1 opened 3 years ago

kdy1 commented 3 years ago

It seems like a misdesign.

Problems

Convenience

API is tricky because of comments.

Performance

The current design makes fixer slow because it requires moving comments in hashmap again and again. Moving comments involves acquiring / releasing lock and rehashing.

It can be improved using buffer, but maybe there is a fundamental problem.

cc @dsherret as you may be interested in this.

dsherret commented 3 years ago

Yeah, this would be good. I also still think there are race conditions in with_leading and with_trailing where two threads might remove one after the other and one thread would end up with different comments.

https://github.com/swc-project/swc/blob/f44e25c3afba2470e8013b757a6bacf30614b1f9/common/src/comments.rs#L291

Edit: I have opened #2001 which fixes this race condition until the redesign.