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

can't use types with internal mutability such as mutex. #13

Closed
alkeryn opened this issue May 9, 2024 · 8 comments
Closed

can't use types with internal mutability such as mutex. #13

alkeryn opened this issue May 9, 2024 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@alkeryn
Copy link

alkeryn commented May 9, 2024

if you try to use let's say a mutex within a soar struct, the compiler will complain.

@tim-harding tim-harding added the bug Something isn't working label May 9, 2024
@tim-harding tim-harding self-assigned this May 9, 2024
@tim-harding
Copy link
Owner

Seems that this is an issue related to const-initialization of Array types related to rust-lang/rust#80384. These types are no longer generated in 0.6.1 unless #[soa_array] is specified.

@alkeryn
Copy link
Author

alkeryn commented May 9, 2024

hey thank you for fixing it that quickly !
btw i was wondering if it is possible for a soa array to have a specific field that is not turned into an array.

let's say you wanted a field shared for all instances but the others to be classic soa ?

btw this crate rocks !

@tim-harding
Copy link
Owner

If what you're after is the SOA array with interior mutability, I think a better option would be to conditionally disable const for the constructor and keep all the same fields. You wouldn't be able to create arrays in const contexts, but for local variables it might still be zero-cost after inlining and constant propagation.

@tim-harding
Copy link
Owner

Following up @alkeryn, is that something that would work for your problem?

@alkeryn
Copy link
Author

alkeryn commented May 14, 2024

i'm not exactly sure, the reason i'd have done it is to have a mutable type multiple thread can work on without locking the whole structure if they only need to access the nth index.

regarding the single variable thing what i meant is to have fields that are soa and some where there is only one instance for all structs.
one example of the generated struct would be:

struct Foo {
field1: Vec<u32>,
field2: String // this field would not generate a vec
}

also how does nesting works with this crate?
i like the way soa-derive kind of suport it :
image

but i'm not sure i can do something like

struct foo {}
struct bar {
foo: Soa<foo>
}
struct foobar {
bar: Soa<bar>
}

@tim-harding
Copy link
Owner

I'm pretty sure with a Mutex field you would still be able to take the lock for a particular element without locking the whole structure. For the single field thing, I'd suggest just putting the SOA inside another struct with the field you don't want to duplicate. The SOA nesting is pretty cool and I would like to add it at some point, but for now you just have to do some copy-paste if you want the same fields in different SOA types.

@alkeryn
Copy link
Author

alkeryn commented May 15, 2024

alright, well either way, thank you for this wonderful crate !
also i can attest to the amazing performance, i'd like to dig into it futher into exactly how it is that much faster but it does perform faster than soa-derive or just a manual implementation with Vec and preallocated size.
soa-derive was around the same ballparck as manual by maybe 1%.

on some custom spiking neural network code this crate was 30% faster than either soa-derive or the manual implementation with vec without changing the algo at all.
thank you ! :)

@tim-harding
Copy link
Owner

Glad to hear you were able to achieve some real-world performance wins. That's gratifying to hear :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants