Skip to content

Conversation

@marek-safar
Copy link
Contributor

to reduce SPC size by about 10k and avoid allocating huge string on the heap

Fixes #45129

to reduce SPC size by about 10k and avoid allocating huge string on the heap

Fixes dotnet#45129
@ghost
Copy link

ghost commented Nov 28, 2020

Tagging subscribers to this area: @tarekgh, @safern, @krwq
See info in area-owners.md if you want to be subscribed.

Issue Details

to reduce SPC size by about 10k and avoid allocating huge string on the heap

Fixes #45129

Author: marek-safar
Assignees: -
Labels:

area-System.Globalization

Milestone: -

{
return (left);
// Binary search the array
while (lo <= hi) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: The corefx coding conventions have { on new line.

@vargaz
Copy link
Contributor

vargaz commented Nov 28, 2020

What generates the new table ?

@marek-safar
Copy link
Contributor Author

What generates the new table ?

There is a short program included at the top as comment

@tarekgh
Copy link
Member

tarekgh commented Nov 29, 2020

There is opportunity to optimize more here by removing the whole LCID tables/data and use the ICU APIs https://unicode-org.github.io/icu-docs/apidoc/dev/icu4c/uloc_8h.html#a5a5d08ba5eca798e1ee9e3eb981d6b39 and https://unicode-org.github.io/icu-docs/apidoc/dev/icu4c/uloc_8h.html#af513851228029d0e63316af1d0039fd8

but this can done be later and don't have to block this PR.

Thanks @marek-safar for getting this done.

@marek-safar marek-safar merged commit e039b92 into dotnet:master Nov 30, 2020
@marek-safar marek-safar deleted the rt branch November 30, 2020 09:13
// Table which holds index into LocalesNames data and length of the string for each locale
// Values are binary searched and need to be sorted alphabetically
//
private static ushort[] s_localesNamesIndexes = new ushort[CulturesCount]
Copy link
Member

Choose a reason for hiding this comment

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

readonly


Console.WriteLine("};");

Console.WriteLine("private static ushort[] s_localesNamesIndexes = new ushort [] {");
Copy link
Member

Choose a reason for hiding this comment

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

private static readonly ushort[] s_localesNamesIndexes


Debug.Assert(s_localeNamesIndices[s_localeNamesIndices.Length - 1] == c_localeNames.Length);
Span<byte> lower_case = stackalloc byte[name.Length];
Copy link
Member

Choose a reason for hiding this comment

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

Could the name that comes in here ever be provided by a caller, such that (in an erroneous case) this could crash with a stack overflow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

0x7c68 << 16 | 1555 << 4 | 7, // ha-latn
0x7c86 << 16 | 2444 << 4 | 8, // quc-latn
0x7c92 << 16 | 1888 << 4 | 7, // ku-arab
0x1007f << 16 | 3175 << 4 | 11, // x-iv_mathan
Copy link
Member

Choose a reason for hiding this comment

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

These overflow 0x1007f and are truncated 0x007f; working on a fix

Copy link
Member

Choose a reason for hiding this comment

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

Fix is in #45643

@jkotas jkotas added tenet-performance Performance related issue linkable-framework Issues associated with delivering a linker friendly framework labels Dec 6, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Globalization linkable-framework Issues associated with delivering a linker friendly framework tenet-performance Performance related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize storage for IcuLocaleData data

8 participants