←back to thread

451 points birdculture | 1 comments | | HN request time: 0.346s | source
Show context
ajross ◴[] No.43980170[source]
> Use String and clone() and unwrap generously; you can always refactor later

At that point you might as well be writing Java or Go or whatever though. GC runtimes tend actually to be significantly faster for this kind of code, since they can avoid all those copies by sharing the underlying resource. By the same logic, you can always refactor the performance-critical stuff via your FFI of choice.

replies(5): >>43980203 #>>43980432 #>>43980632 #>>43981812 #>>43981902 #
1. nemothekid ◴[] No.43981812[source]
>significantly faster for this kind of code

"Significantly" and "this kind" are load bearing sentences here. In applications where predictable latency is desired, cloning is better than GC.

This is also the baby steps of learning the language. As a programmer gets better they will recognize when they are making superflous clones. Refactoring performance-critical stuff in FFI, however, is painful and wont get easier with time.

Furthermore, in real applications, this only really applies to Strings and vectors. In most of my applications most `clones` are of reference types - which is only marginally more expensive than memory sharing under a GC.