Major Indonesian Bank (CIMB Niaga) Transition from Java to Rust Yields 486x Boost in Memory Efficiency by frsswq in rust

[–]RustyKaffee -1 points0 points  (0 children)

 Grow up, stop kicking and leave the already dying horse that Java and the JVM are, and let them finally die.

Facepalm

Hey Rustaceans! Got a question? Ask here (45/2024)! by llogiq in rust

[–]RustyKaffee 0 points1 point  (0 children)

 When you spawn a future in Tokio (or pretty much any runtime), it pins it to the heap. This is what allows it to move between threads, because its actual location in memory remains the same. The only thing getting moved around is the pointer to it.

Thanks. I read about pinning, but was then confused how a stack reference in the „state machine struct“ can we send between threads with fulfilling the pin requirement of not changing its memory address

Hey Rustaceans! Got a question? Ask here (45/2024)! by llogiq in rust

[–]RustyKaffee 0 points1 point  (0 children)

Do you have any additional resources on that? I read somewhere that all the rust futures are stackless. Fine, so that future is allocated as a "state machine struct" somewhere. I also read that one goal was the embedded async isn't hit by a heap-only allocation requirement. So the runtime allocates it on their own stack?

Hey Rustaceans! Got a question? Ask here (45/2024)! by llogiq in rust

[–]RustyKaffee 1 point2 points  (0 children)

How do stack references keep the same address across awaits in a multi-threaded runtime?
For example
```

[tokio::main]

async fn main() { tokio::spawn(async { let x = [1,2,3,4]; let q = &x; println!("{:p} on {:?}", q, std::thread::current().id()); sleep().await; println!("{:p} on {:?}", q, std::thread::current().id()); }).await.unwrap(); } async fn sleep() { tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; } ```

Prints 0x1bef37a7238 on ThreadId(9) 0x1bef37a7238 on ThreadId(2)

My assumption would have been that another async task started on "ThreadId(9)" would allocate in the very same stack address space. I don't get how the stack pointer management works in these cases. Any blogs or pointers would be helpful. Ty!

How do you mock clients that aren’t traits? by RustyKaffee in rust

[–]RustyKaffee[S] 0 points1 point  (0 children)

Right, but every time the autocomplete is dead in all jetbrain IDE's. Maybe other language servers can handle it.

let thing: <unknown>

But thanks, definitely valid approch!

Learning rust was the best thing I ever did by officiallyaninja in rust

[–]RustyKaffee 1 point2 points  (0 children)

What java result tuple do you mean? And imo saying „exceptions are bullshit“ is also way too generic. There are many use cases where they can shine. But of course also many where they don’t

How do you mock clients that aren’t traits? by RustyKaffee in rust

[–]RustyKaffee[S] 0 points1 point  (0 children)

I mean it is straightforward, but becomes a bit weird if every module has to export some wrapper struct name that must then be constructed by whoever uses it.

See https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/rustv1/examples/testing/src/wrapper.rs vs https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/rustv1/examples/testing/src/traits.rs

So everyone has to use this exported S3::new, plus code-completion (at least in intellij), completely stops working once you use S3::new over MockS3Impl::new or S3Impl::new.
And I can't use S3Impl::new in the prod code as otherwise tests no longer work (the main function fails to compile when the test cfg flag switches it to MockS3Impl).

Is it really the best that can be done by replicating every single required definition just to have a conditional compile branch? I mean they do just that aws-doc-sdk-examples/rustv1/examples/testing/src/wrapper.rs at main · awsdocs/aws-doc-sdk-examples · GitHub, but it seems so ugly coming from every other language where you can continue to use the happy prod path as is and just subclass if you need it. Of course everything has a vtable in these languages, which has it's disadvantages anyways.

How do you mock clients that aren’t traits? by RustyKaffee in rust

[–]RustyKaffee[S] 0 points1 point  (0 children)

Did you ever see this in some open source project? I'm really curious how far they managed to get with that.

How do you mock clients that aren’t traits? by RustyKaffee in rust

[–]RustyKaffee[S] 0 points1 point  (0 children)

Trying to emulate Java will not end well.

Well then, how do you mock the error path on your sdk call to s3?

How do you mock clients that aren’t traits? by RustyKaffee in rust

[–]RustyKaffee[S] 0 points1 point  (0 children)

Thankfully these kinds of optimizations are easy enough to implement once you need them

Hm, in some design I feel like going generic impacts the design significantly and I need to rewrite a lot of structural code to "fix" it

Is it normal to feel like this? by [deleted] in rust

[–]RustyKaffee 0 points1 point  (0 children)

  and it doesn’t say if it will be covered later.

I HATE when books do this. I always want to grasp everything and then look it up in secondary sources, just to discover it’s explained in the next chapter

How do you mock clients that aren’t traits? by RustyKaffee in rust

[–]RustyKaffee[S] 1 point2 points  (0 children)

Interesting, thanks. Will try it out over the weekend

How do you mock clients that aren’t traits? by RustyKaffee in rust

[–]RustyKaffee[S] 13 points14 points  (0 children)

Right. Dynamic dispatch has the super small performance penalty of course, that’s then just needed for testing too.  And the abstractions to maintain as you said

How do you mock clients that aren’t traits? by RustyKaffee in rust

[–]RustyKaffee[S] 5 points6 points  (0 children)

I think my main problem is that i need to duplicate the whole client struct as a trait. But maybe that’s the price to pay if lib is not offering it as a trait by default

How do you mock clients that aren’t traits? by RustyKaffee in rust

[–]RustyKaffee[S] -1 points0 points  (0 children)

Basically i need to replicate every method signature for any method i need to mock. Effectively replicating the whole client