Skip to content

Conversation

hsivonen
Copy link
Member

Inspired by discovering how Firefox and Thunderbird UI code uses collation and pondering whether it makes sense.

@hsivonen hsivonen requested a review from echeran as a code owner June 12, 2025 11:16
Copy link

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

@Manishearth
Copy link
Member

  • @hsivonen (missed)
  • @sffc henri i had a couple comments on your PR, will post.
  • @hsivonen If you want better performance you shouldn't lower the strength won't get that much better perf. but you'll have user visible weirdness
  • @hsivonen but if you have a larger struct with a string field and want to sort on the string field ignoring case and accents then you have multiple ?? equals at that leevel. you can break the tie with the accents, then that's fine.
  • @sffc yeah we should state concisely when this isn't the tool for the job just for perf.

Copy link
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some pending comments I neglected to post

@@ -15,13 +15,45 @@ use crate::{
CollatorPreferences,
};

/// The collation strength that indicates how many levels to compare.
/// The collation strength that indicates how many levels to compare. The primary
/// level considers base letters, i.e. 'a' and 'b' are unequal but 'E' and 'é'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it guaranteed to be the "base letter"? How does that map to other writing systems, or to locales that sort certain diacritics nonadjacent to their base letter (like Danish Å)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the one hand: I don't think it's guaranteed to be a base letter, per se. For example, the Rupee sign U+20A8 used to sort with other currency symbols. Now it sorts with the ASCII letter sequence "Rs". The German sharp S (ß) sorts with ss, I believe.

On the other hand: the ICU User Guide uses the terms "base letter" and "base character": https://unicode-org.github.io/icu/userguide/collation/concepts.html

I think we can reuse ICU terminology for ICU4X docs, at least here for the purposes of illustrating the effects of different strength levels to explain strength.

Comment on lines +28 to +31
/// compare as equal. This may make sense when sorting more complex structures
/// where the string to be compared is just one field, and ties between strings
/// that differ only in case, accent, or similar are resolved by comparing some
/// secondary field in the larger structure to be sorted.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this use case actually make sense? You say in the next paragraph that it doesn't really make sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the subsequent paragraph is just expounding on the main point of this paragraph. If so, then I think that the subsequent beginning with the word "However" is confusing for the reader.

@@ -15,13 +15,45 @@ use crate::{
CollatorPreferences,
};

/// The collation strength that indicates how many levels to compare.
/// The collation strength that indicates how many levels to compare. The primary
/// level considers base letters, i.e. 'a' and 'b' are unequal but 'E' and 'é'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the one hand: I don't think it's guaranteed to be a base letter, per se. For example, the Rupee sign U+20A8 used to sort with other currency symbols. Now it sorts with the ASCII letter sequence "Rs". The German sharp S (ß) sorts with ss, I believe.

On the other hand: the ICU User Guide uses the terms "base letter" and "base character": https://unicode-org.github.io/icu/userguide/collation/concepts.html

I think we can reuse ICU terminology for ICU4X docs, at least here for the purposes of illustrating the effects of different strength levels to explain strength.

//! The degree of sensitivity in how to determine that strings are distinct.
//! The collation strength indicates how many levels to compare. The primary
//! level considers base letters, i.e. 'a' and 'b' are unequal but 'E' and 'é'
//! are equal, with further levels dealing with distinctions such as accents
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify that the "high" / "low" relationship corresponds to primary = lowest, indentical = highest

Suggested change
//! are equal, with further levels dealing with distinctions such as accents
//! are equal, with higher levels dealing with distinctions such as accents

Comment on lines +75 to +77
//! If an earlier level isn't equal, the earlier level is decisive.
//! If the result is equal on a level, but the strength is higher,
//! the comparison proceeds to the next level.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! If an earlier level isn't equal, the earlier level is decisive.
//! If the result is equal on a level, but the strength is higher,
//! the comparison proceeds to the next level.
//! If an lower level isn't equal, the lower level is decisive.
//! If the comparison result is equal on one level,
//! but the collator's strength input value is higher than that,
//! then the collator comparison iteratively proceeds to the next higher level.

Comment on lines +79 to +80
//! Note that lowering the strength means that more user-perceptible differences
//! compare as equal. This may make sense when sorting more complex structures
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! Note that lowering the strength means that more user-perceptible differences
//! compare as equal. This may make sense when sorting more complex structures
//! Note that lowering the strength value given to the collator means that more user-perceptible
//! differences will compare as equal. This may make sense when sorting more complex structures

//! compare as equal. This may make sense when sorting more complex structures
//! where the string to be compared is just one field, and ties between strings
//! that differ only in case, accent, or similar are resolved by comparing some
//! secondary field in the larger structure to be sorted.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: you could mention that some browsers implement the "Find" functionality for a page based on collation, ex: via the StringSearch API in ICU. This allows them to choose between primary strength so that it can ignore diacritics and case ("koln" matching on "Köln") or secondary strength to only match exactly on diacritics ("Bár" not matching "Bär").

//! that differ only in case, accent, or similar are resolved by comparing some
//! secondary field in the larger structure to be sorted.
//!
//! However, if the sort is just a string sort without some other field for
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general for this paragraph, I think it should be worded as a detailed caution to the user. It expounds on the main point of the previous paragraph, IMO.

Suggested change
//! However, if the sort is just a string sort without some other field for
//! Therefore, if the sort is just a string sort without some other field for

//! provide the stability property) affect the relative order of strings that
//! do have user-perceptible differences particularly in accents or case.
//!
//! Lowering the strength is less of a perfomance optimization that it may seem
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! Lowering the strength is less of a perfomance optimization that it may seem
//! Lowering the strength is less of a perfomance optimization than it may seem

//! Lowering the strength is less of a perfomance optimization that it may seem
//! directly from the above description. As described above, in the case
//! of identical strings to be compared, the algorithm has to work though all
//! the levels included in the strength without an early exit. However, this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! the levels included in the strength without an early exit. However, this
//! the levels, from primary up to the provided strength value given to collator, without an early exit. However, this

Comment on lines +28 to +31
/// compare as equal. This may make sense when sorting more complex structures
/// where the string to be compared is just one field, and ties between strings
/// that differ only in case, accent, or similar are resolved by comparing some
/// secondary field in the larger structure to be sorted.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the subsequent paragraph is just expounding on the main point of this paragraph. If so, then I think that the subsequent beginning with the word "However" is confusing for the reader.

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.

4 participants