longbridgeapp / rust-i18n

A better and simply I18n crate for Rust.
MIT License
297 stars 32 forks source link

Add chained fallback support and performance improved #69

Closed varphone closed 8 months ago

varphone commented 8 months ago

New:

sunli829 commented 8 months ago
rust_i18n::locale() -> String => rust_i18n::locale() -> Arc<str>

Arc<str> is better than Arc<String>, what do you think?

huacnlee commented 8 months ago

Update this new benchmark result to README.md

t                       time:   [58.274 ns 60.222 ns 62.390 ns]
t_with_locale           time:   [55.395 ns 57.106 ns 59.081 ns]
t_with_args             time:   [167.46 ns 170.94 ns 175.64 ns]
t_with_args (str)       time:   [164.85 ns 165.91 ns 167.41 ns]
t_with_args (many)      time:   [444.04 ns 452.17 ns 463.44 ns]
t_with_threads          time:   [414.26 ns 422.97 ns 433.53 ns]
varphone commented 8 months ago
rust_i18n::locale() -> String => rust_i18n::locale() -> Arc<str>

Arc<str> is better than Arc<String>, what do you think?

The AtomicPtr

rust_i18n::locale() -> String => rust_i18n::locale() -> Arc<str>

Arc<str> is better than Arc<String>, what do you think?

AtomicStr needs to hold the string content, which must be stored using a String. Putting the String into Arc can achieve zero-copy reference, so returning Arc<String> directly is the most efficient way. If use Arc<str> as the return the value will produce a memory copy.

huacnlee commented 8 months ago

https://github.com/longbridgeapp/rust-i18n/releases/tag/v2.4.0