core icon indicating copy to clipboard operation
core copied to clipboard

[Feature] Move alloc feature behind a feature gate

Open Pzixel opened this issue 4 months ago • 6 comments

Component

primitives

Describe the feature you would like

I've checked the codebase, and two types that are used from the alloc crate are String and vec.

There is a possibility to move remove the alloc dependency from the crate. The only type that will be disabled by that is Bytes - but all Uxxx and Ixxx math, Address type and others will remain.

There is a bunch of formatting that use String here and there, but it all can be replaced with on-stack buffers (stack-based arrayvec::ArrayString can be used instead), because for all those cases we either know the exact buffer size of at least the maximum possible string size.

I think is reasonable to assume that primitive_types can work without the alloc, hence this issue. I can work on an implementation if this is something you consider to be accepted.

Additional context

No response

Pzixel avatar Aug 29 '25 15:08 Pzixel

I think that's fair but only for alloy-primitives, the other crates make heavy use of these types

DaniPopes avatar Aug 29 '25 16:08 DaniPopes

Right, I'm talking about the primitives only.

Pzixel avatar Sep 01 '25 06:09 Pzixel

@DaniPopes @Pzixel can i take this up?

SWASTIC-7 avatar Sep 17 '25 05:09 SWASTIC-7

@Pzixel , I am changing the String with fixed size pub type String = ArrayString<80>;, There is lot of usage of Vec which are of dynamic size, do they also need to be changed to ArrayVec as in many case we don't know the size at compile time I guess? We are also using Result<Box<MaybeUninit<T>>, TryReserveError> which depends on alloy crate and i think we cannot completly get rid of the crate.

SWASTIC-7 avatar Sep 18 '25 21:09 SWASTIC-7

@SWASTIC-7 Stack strings are only okay if you know the max length it will be. It's true for most of the types in the crate (like U256 for instance), but there are a lot of types that are inherently arbitrary sized. Then they can remain behind the feature gate, if they are naturally depending on this feature nothing you can do about it.

Pzixel avatar Sep 18 '25 22:09 Pzixel

@Pzixel ok then I will make pr by changing the strings to stacked string wherever possible

SWASTIC-7 avatar Sep 18 '25 22:09 SWASTIC-7