[perf] Constructors where `this` escapes are slow
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- compilers, performance
Hướng nghiên cứu
The issue describes how the translator emits constructors for C++ types whose this escapes, so start in the code that generates the Rust new function for constructors. Read the godbolt example linked in the issue to compare the inline and escaping cases. The proposed change is to allocate the storage before the constructor call and pass it in; done means escaping-this output no longer copies the struct and the existing transpiler tests still pass. The Rc/RefCell case is a separate, related cost.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
In unsafe constructors are translated as:
fn new() -> Self {
let this = Self { ... };
... body of the constructor ...
this
}
When this escapes in the body of the constructor, for example init(&mut this), the translated new becomes slower than necessary: this is constructed inside the body then memcpy'ed in the caller.
When this does not escape in the body of the constructor, Rust returns the this inline, without a memcpy. See this example.
C++ does no memcpy. The semantics of the constructor is: a storage, i.e. this, is passed to the constructor, the constructor initialises this, then the storage is returned.
I think that the solution for this performance problem is to follow what C++ does: create this before calling the constructor and pass the storage to the constructor. This would also fix #248.
In performance terms, refcount is worse because it does 3 memcpy's even when this does not escape:
fn new() -> Self {
let __this = Rc::new(RefCell::new(Self { ... }));
let this = __this.as_pointer();
Rc::try_unwrap(this) // memcpy 1: transforms Rc<RefCell<S>> into Result<RefCell<S>, Rc<RefCell<S>>>
.ok().unwrap() // memory 2: transforms Result<RefCell<S>, Rc<RefCell<S>>> into RefCell<S>
.into_inner() // memcp 3: transforms RefCell<S> into S
}
The solution is the same as unsafe: create this before calling the constructor and pass the storage to the constructor.
- Ngôn ngữ chính
- Rust
- Star
- 310
- Fork
- 18
- Merge trung bình
- 10 giờ 18 phút
- Pull request đã merge (30 ngày)
- 125
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Cpp2Rust/cpp2rust
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 55/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 56/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 56/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Cpp2Rust/cpp2rust
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
higress-group/HiRoute#405 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
rust_analyzer flycheck: no CLI way to enable clippy from `check.overrideCommand`Có thể đã có người làm @TrapsterDK đã nhận hôm nay. Đang mởneeds-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
bazelbuild/rules_rust#4392 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
🐞 bug 🧩 bevy_gantz_egui
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
nannou-org/gantz#500 ·
Maintainer thường phản hồi trong vòng 1 ngày