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

Add chained fallback support and performance improved #69

Merged
merged 16 commits into from
Jan 19, 2024

Conversation

varphone
Copy link
Contributor

@varphone varphone commented Jan 18, 2024

New:

Improved:

  • Remove RwLock from locale() and set_locale().
  • String patterns replacement, time reduce 10% ~ 80%.
  • Reduce memory copy on t!().

Breaking Changes:

  • rust_i18n::locale() -> String => rust_i18n::locale() -> Arc<String> .
  • t!() -> String => t!() -> Cow<str>.

@varphone varphone changed the title Many fallback and performance improved Add chained fallback support and performance improved Jan 18, 2024
@sunli829
Copy link
Contributor

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

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

@huacnlee
Copy link
Member

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
Copy link
Contributor Author

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 huacnlee merged commit 91abcd6 into longbridgeapp:main Jan 19, 2024
2 checks passed
@huacnlee
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants