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

refactor(error): reduce error type size #11275

Merged
merged 13 commits into from
Aug 1, 2023
Merged

Conversation

wangrunji0408
Copy link
Contributor

@wangrunji0408 wangrunji0408 commented Jul 27, 2023

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

This PR reduces size of the following error types:

Error Before Size After Size
StreamError 240 8
StreamExecutorError 240 8
ExprError 184 40
UdfError 184 32
RpcError 176 16

by boxing the error body and offloading them to the heap.

The common pattern of this technique is:

pub struct Error {
    inner: Box<Inner>,
}
struct Inner {
    kind: ErrorKind,
    backtrace: Backtrace,
}
enum ErrorKind {
    Storage(StorageError),
    ...
}

This partially resolves #11263.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR contains user-facing changes.

Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
@wangrunji0408
Copy link
Contributor Author

I'm considering whether the ExprError is also worth reducing to 8 bytes. Because it's used in scalar functions which are also performance sensitive.

Copy link
Member

@xxchan xxchan left a comment

Choose a reason for hiding this comment

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

🔥🥵

  • merge StreamExecutorError and StreamError: not sure. What’s the reason? I generally prefer more fine-grained error types, if no much trouble introduced, because it made clear what’s possible errors for a function.
  • XxError -> Error. Not sure. Personally slightly prefer the former, but no strong opinions.

Others lgtm

@wangrunji0408
Copy link
Contributor Author

merge StreamExecutorError and StreamError: not sure. What’s the reason? I generally prefer more fine-grained error types, if no much trouble introduced, because it made clear what’s possible errors for a function.

I found the main body of stream crate is the executors. Having two error types cause double memory usage in most cases. And I prefer one unified error type in one crate.

XxError -> Error. Not sure. Personally slightly prefer the former, but no strong opinions.

In most 3rd party libraries and std library, their error types are named Error. 🤔

@BugenZhao
Copy link
Member

And I prefer one unified error type in one crate.

Personally, I prefer to keep the granularity as fine as possible. 😰 Currently the difference between StreamError and StreamExecutorError is kind of clear. The former is for controllers and managers, and the latter is for executor computations.

Similar ideas are applied to expression as well. -> #10764

@wangrunji0408 wangrunji0408 force-pushed the wrj/reduce-error-size branch from e713c14 to 810dead Compare July 28, 2023 06:56
@TennyZhuang
Copy link
Contributor

I'd prefer split Error instead of merge Error.

Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
@wangrunji0408 wangrunji0408 force-pushed the wrj/reduce-error-size branch from 810dead to a434571 Compare July 28, 2023 06:59
@wangrunji0408 wangrunji0408 changed the title refactor(error): reduce error type size and rename them to Error refactor(error): reduce error type size Jul 28, 2023
@wangrunji0408
Copy link
Contributor Author

Reverted merging and renaming. PTAL again. 🤡

Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
@codecov
Copy link

codecov bot commented Jul 28, 2023

Codecov Report

Merging #11275 (f4d371e) into main (a84d8e1) will decrease coverage by 0.01%.
Report is 1 commits behind head on main.
The diff coverage is 19.19%.

@@            Coverage Diff             @@
##             main   #11275      +/-   ##
==========================================
- Coverage   69.79%   69.78%   -0.01%     
==========================================
  Files        1359     1360       +1     
  Lines      225851   225880      +29     
==========================================
+ Hits       157630   157635       +5     
- Misses      68221    68245      +24     
Flag Coverage Δ
rust 69.78% <19.19%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
src/batch/src/executor/hop_window.rs 75.24% <0.00%> (-0.25%) ⬇️
src/expr/src/error.rs 21.05% <0.00%> (ø)
src/expr/src/expr/test_utils.rs 84.51% <0.00%> (-2.24%) ⬇️
src/expr/src/vector_op/date_trunc.rs 6.25% <0.00%> (ø)
src/expr/src/vector_op/encdec.rs 72.72% <0.00%> (ø)
src/expr/src/vector_op/jsonb_info.rs 15.38% <0.00%> (ø)
src/expr/src/vector_op/overlay.rs 94.02% <0.00%> (ø)
src/expr/src/vector_op/trim_array.rs 4.54% <0.00%> (ø)
...tend/src/optimizer/plan_node/generic/hop_window.rs 91.32% <0.00%> (-1.15%) ⬇️
src/rpc_client/src/error.rs 8.33% <0.00%> (-8.34%) ⬇️
... and 12 more

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

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

Rest LGTM

Signed-off-by: Runji Wang <wangrunji0408@163.com>
Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

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

LGTM! Really appreciate.

@MrCroxx
Copy link
Contributor

MrCroxx commented Aug 1, 2023

Nice! Looking forward to seeing the performance!

Signed-off-by: Runji Wang <wangrunji0408@163.com>
@wangrunji0408 wangrunji0408 force-pushed the wrj/reduce-error-size branch from 375565f to f4d371e Compare August 1, 2023 08:53
@wangrunji0408 wangrunji0408 enabled auto-merge August 1, 2023 08:55
@wangrunji0408 wangrunji0408 added this pull request to the merge queue Aug 1, 2023
Merged via the queue into main with commit 1538c97 Aug 1, 2023
@wangrunji0408 wangrunji0408 deleted the wrj/reduce-error-size branch August 1, 2023 10:14
wangrunji0408 added a commit that referenced this pull request Aug 4, 2023
Signed-off-by: Runji Wang <wangrunji0408@163.com>
lmatz pushed a commit that referenced this pull request Aug 4, 2023
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants