opendal icon indicating copy to clipboard operation
opendal copied to clipboard

OperatorInfo should be stored inside Operator to avoid calling metadata

Open Xuanwo opened this issue 1 year ago • 11 comments

OperatorInfo will never be changed after Operator been built, we can store it inside an Arc inside Operator to avoid extra cost.

Xuanwo avatar Jul 02 '24 10:07 Xuanwo

If my understanding is right, it just wrap OperatorInfo in Arc<T>.

And if it is better to use OnceCell<T> for lazy init of OperatorInfo and change pub fn info(&self) -> OperatorInfo to pub fn info(&self) -> &OperatorInfo?

Lzzzzzt avatar Jul 11 '24 01:07 Lzzzzzt

Hi, @Lzzzzzt. Thanks for joining the discussion and starting https://github.com/apache/opendal/pull/4883.

After some consideration, I think it would be better to modify Access::info() to return Arc<AccessInfo>, similiar to what you suggested in https://github.com/apache/opendal/pull/4883#issuecomment-2224328372. This will allow all our layers to avid extra copy.

With this change, OperatorInfo could hold an Arc<AccessInfo>, allowing the user API to remain unchanged.

Xuanwo avatar Jul 12 '24 03:07 Xuanwo

Hi, @Lzzzzzt. Thanks for joining the discussion and starting #4883.

After some consideration, I think it would be better to modify Access::info() to return Arc<AccessInfo>, similiar to what you suggested in #4883 (comment). This will allow all our layers to avid extra copy.

With this change, OperatorInfo could hold an Arc<AccessInfo>, allowing the user API to remain unchanged.

Ok, got it

Lzzzzzt avatar Jul 12 '24 03:07 Lzzzzzt

Hi, @Lzzzzzt. Thanks for joining the discussion and starting #4883.

After some consideration, I think it would be better to modify Access::info() to return Arc<AccessInfo>, similiar to what you suggested in #4883 (comment). This will allow all our layers to avid extra copy.

With this change, OperatorInfo could hold an Arc<AccessInfo>, allowing the user API to remain unchanged.

It seems need to change a lot, if modify Access::info() to return Arc<AccessInfo>

Lzzzzzt avatar Jul 12 '24 03:07 Lzzzzzt

It seems need to change a lot, if modify Access::info() to return Arc<AccessInfo>

Yes. If we do need API breaking changes, I prefer change opendal::raw API instead of opendal's public API.

Xuanwo avatar Jul 12 '24 03:07 Xuanwo

It seems need to change a lot, if modify Access::info() to return Arc<AccessInfo>

Yes. If we do need API breaking changes, I prefer change opendal::raw API instead of opendal's public API.

if modify Access::info() to return Arc<AccessInfo>, a lot of struct will need a extra field to store the info, is that right?

https://github.com/apache/opendal/blob/740928efffc761a22fdf4bb3300e25ab790616b2/core/src/services/fs/backend.rs#L184-L210

Lzzzzzt avatar Jul 12 '24 05:07 Lzzzzzt

if modify Access::info() to return Arc, a lot of struct will need a extra field to store the info, is that right?

We can start by simply adding an into() and refactor them later based on our feedback.

Xuanwo avatar Jul 12 '24 05:07 Xuanwo

some layers need a mutable AccessorInfo, so Arc<T> may not work

https://github.com/apache/opendal/blob/740928efffc761a22fdf4bb3300e25ab790616b2/core/src/layers/blocking.rs#L168-L185

Lzzzzzt avatar Jul 12 '24 05:07 Lzzzzzt

some layers need a mutable AccessorInfo, so Arc<T> may not work

Those layers can build a new AccessorInfo with changed value.

Xuanwo avatar Jul 12 '24 05:07 Xuanwo

some layers need a mutable AccessorInfo, so Arc<T> may not work

Those layers can build a new AccessorInfo with changed value.

ok

Lzzzzzt avatar Jul 12 '24 05:07 Lzzzzzt

I change the signature of Access::info and AccessDyn::info and related layers implement, and fs service. PTAL

Lzzzzzt avatar Jul 12 '24 06:07 Lzzzzzt

Has been implemented, closing.

Xuanwo avatar Nov 14 '24 07:11 Xuanwo