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

Optimize huffman encoding static table initialization #45303

Conversation

rokonec
Copy link
Contributor

@rokonec rokonec commented Nov 28, 2020

Reasoning is in #45297

@ghost
Copy link

ghost commented Nov 28, 2020

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Reasoning is in #45297

Author: rokonec
Assignees: -
Labels:

area-System.Net.Http

Milestone: -

@rokonec
Copy link
Contributor Author

rokonec commented Nov 28, 2020

Although it feels fragile to split it into two array, I feel confident about this changes as unit tests have their own copy of encoding table

TheoryData<int, uint, int> data = new TheoryData<int, uint, int>();
and cover all encoding table items.

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

Other than my comments, LGTM. Thanks.

@benaadams
Copy link
Member

runtime (Libraries Test Run release coreclr windows x86 Release)

System.Text.Encodings.Web.Tests.UnicodeHelpersTests.GetUtf8RepresentationForScalarValue

Error message
System.ArgumentNullException : Value cannot be null. (Parameter 'type')

Stack trace
   at System.Reflection.IntrospectionExtensions.GetTypeInfo(Type type) in /_/src/libraries/System.Private.CoreLib/src/System/Reflection/IntrospectionExtensions.cs:line 11
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext() in /_/src/libraries/System.Linq/src/System/Linq/Select.cs:line 186
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() in /_/src/libraries/System.Linq/src/System/Linq/Where.cs:line 391
   at System.Linq.Enumerable.Contains[TSource](IEnumerable`1 source, TSource value, IEqualityComparer`1 comparer) in /_/src/libraries/System.Linq/src/System/Linq/Contains.cs:line 23
   at System.Linq.Enumerable.Contains[TSource](IEnumerable`1 source, TSource value) in /_/src/libraries/System.Linq/src/System/Linq/Contains.cs:line 11
   at System.Text.Encodings.Web.Tests.UnicodeHelpersTests.GetUtf8RepresentationForScalarValue() in /_/src/libraries/System.Text.Encodings.Web/tests/UnicodeHelpersTests.cs:line 107

Error is unrelated; but odd as is a null type 🤔

@stephentoub
Copy link
Member

stephentoub commented Nov 29, 2020

That stack makes no sense to me; it's pointing to

Assert.Equal(expectedUtf8Bytes, actualUtf8Bytes);
, which doesn't use Select.Where.Contains. @trylek, could this be fallout from the crossgen2 change somehow? This same test has been failing on other PRs this weekend, e.g. https://dev.azure.com/dnceng/public/_build/results?buildId=902244&view=ms.vss-test-web.build-test-results-tab&runId=28813620&paneView=debug&resultId=174751 from @jkotas.

@benaadams
Copy link
Member

which doesn't use Select.Where.Contains

I assume that's the stack trace for Xunit.Asset.Equal<T>(IEnumerable<T> expected, IEnumerable<T> actual) for List<byte> as Xunit hides its stack frames.

Have been looking at odd release coreclr windows x86 Release null refs in reflection related stacks (this error is one); seeing if I'd broken something in open PR #45121 or whether they are already broken, another is https://dev.azure.com/dnceng/public/_build/results?buildId=902114&view=ms.vss-test-web.build-test-results-tab&runId=28808954&resultId=110325&paneView=debug

System.ComponentModel.Composition.ComposablePartCatalogExportProviderTests.ComponentCatalogResolverGetStaticExport

System.NullReferenceException : Object reference not set to an instance of an object.

at Microsoft.Internal.AttributeServices.IsAttributeDefined[T](ICustomAttributeProvider attributeProvider, Boolean inherit) in /_/src/libraries/System.ComponentModel.Composition/src/Microsoft/Internal/AttributeServices.cs:line 38
   at System.ComponentModel.Composition.AttributedModel.AttributedPartCreationInfo.IsInheritedExport(ICustomAttributeProvider attributedProvider) in /_/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/AttributedModel/AttributedPartCreationInfo.cs:line 423
   at System.ComponentModel.Composition.AttributedModel.AttributedPartCreationInfo.GetInheritedExports(Type type)+MoveNext() in /_/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/AttributedModel/AttributedPartCreationInfo.cs:line 409
   at System.ComponentModel.Composition.AttributedModel.AttributedPartCreationInfo.GetExportDefinitions() in /_/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/AttributedModel/AttributedPartCreationInfo.cs:line 301
   at System.ComponentModel.Composition.AttributedModel.AttributedPartCreationInfo.DiscoverExportsAndImports() in /_/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/AttributedModel/AttributedPartCreationInfo.cs:line 260
   at System.ComponentModel.Composition.AttributedModel.AttributedPartCreationInfo.GetExports() in /_/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/AttributedModel/AttributedPartCreationInfo.cs:line 66
   at System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePartDefinition.get_ExportDefinitionsInternal() in /_/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/ReflectionComposablePartDefinition.cs:line 66
   at System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePartDefinition.get_ExportDefinitions() in /_/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/ReflectionComposablePartDefinition.cs:line 83
   at System.ComponentModel.Composition.Hosting.TypeCatalog.CreateIndex() in /_/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/TypeCatalog.cs:line 322
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode) in /_/src/libraries/System.Private.CoreLib/src/System/Lazy.cs:line 321
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) in /_/src/libraries/System.Private.CoreLib/src/System/Lazy.cs:line 345
   at System.Lazy`1.CreateValue() in /_/src/libraries/System.Private.CoreLib/src/System/Lazy.cs:line 425
   at System.Lazy`1.get_Value() in /_/src/libraries/System.Private.CoreLib/src/System/Lazy.cs:line 505
   at System.ComponentModel.Composition.Hosting.TypeCatalog.GetCandidateParts(String contractName) in /_/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/TypeCatalog.cs:line 312
   at System.ComponentModel.Composition.Hosting.TypeCatalog.GetCandidateParts(ImportDefinition definition) in /_/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/TypeCatalog.cs:line 299
   at System.ComponentModel.Composition.Primitives.ComposablePartCatalog.GetExports(ImportDefinition definition) in /_/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/ComposablePartCatalog.cs:line 104
   at System.ComponentModel.Composition.Hosting.AssemblyCatalog.GetExports(ImportDefinition definition) in /_/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AssemblyCatalog.cs:line 427
   at System.ComponentModel.Composition.Hosting.CatalogExportProvider.InternalGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition) in /_/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/

@stephentoub
Copy link
Member

stephentoub commented Nov 29, 2020

I assume that's the stack trace for Xunit.Asset.Equal(IEnumerable expected, IEnumerable actual)

That was my initial thought as well, though I didn't see that anywhere in the assert code (nor is it clear to me why Contains would be used in such an assert), hence my comment.

@benaadams
Copy link
Member

hence my comment.

Yeah, can't see how it would get there :-/

@benaadams
Copy link
Member

benaadams commented Nov 29, 2020

Sorry @rokonec for this side discussion 😅

@stephentoub a more complete trace from #45310; again on (Libraries Test Run release coreclr windows x86 Release) that looks related (same trace with Xunit but Fatal error. 0xC0000005) https://helixre8s23ayyeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-pull-45310-merge-f380f19a901d423e93/System.Text.Encodings.Web.Tests/console.31ef414e.log?sv=2019-07-07&se=2020-12-19T16%3A41%3A38Z&sr=c&sp=rl&sig=J6tmdBZJgh2VxjCYoed1fJlnVURu6wUExNd29SkhlgU%3D

C:\h\w\A748094D\w\9B3408E2\e>"C:\h\w\A748094D\p\dotnet.exe" exec --runtimeconfig System.Text.Encodings.Web.Tests.runtimeconfig.json --depsfile System.Text.Encodings.Web.Tests.deps.json xunit.console.dll System.Text.Encodings.Web.Tests.dll -xml testResults.xml -nologo -nocolor -notrait category=IgnoreForCI -notrait category=OuterLoop -notrait category=failing  
  Discovering: System.Text.Encodings.Web.Tests (method display = ClassAndMethod, method display options = None)
  Discovered:  System.Text.Encodings.Web.Tests (found 181 test cases)
  Starting:    System.Text.Encodings.Web.Tests (parallel test collections = on, max threads = 2)
Fatal error. 0xC0000005
   at System.Runtime.CompilerServices.CastHelpers.IsInstanceOfInterface(Void*, System.Object)
   at System.Reflection.IntrospectionExtensions.GetTypeInfo(System.Type)
   at Xunit.Sdk.AssertEqualityComparer`1+<>c[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].<IsSet>b__10_0(System.Type)
   at System.Linq.Enumerable+SelectArrayIterator`2[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at System.Linq.Enumerable+WhereSelectEnumerableIterator`2[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at System.Linq.Enumerable.Contains[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Collections.Generic.IEnumerable`1<System.__Canon>, System.__Canon, System.Collections.Generic.IEqualityComparer`1<System.__Canon>)
   at System.Linq.Enumerable.Contains[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Collections.Generic.IEnumerable`1<System.__Canon>, System.__Canon)
   at Xunit.Sdk.AssertEqualityComparer`1[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].IsSet(System.Reflection.TypeInfo)
   at Xunit.Sdk.AssertEqualityComparer`1[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].CheckIfSetsAreEqual(System.__Canon, System.__Canon, System.Reflection.TypeInfo)
   at Xunit.Sdk.AssertEqualityComparer`1[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Equals(System.__Canon, System.__Canon)
   at Xunit.Assert.Equal[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon, System.__Canon, System.Collections.Generic.IEqualityComparer`1<System.__Canon>)
   at Xunit.Assert.Equal[[System.Byte, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Collections.Generic.IEnumerable`1<Byte>, System.Collections.Generic.IEnumerable`1<Byte>)
   at System.Text.Encodings.Web.Tests.UnicodeHelpersTests.GetUtf8RepresentationForScalarValue()
...

@benaadams
Copy link
Member

Raised issue for the null ref #45317 as it definitely looks like a thing

@rokonec
Copy link
Contributor Author

rokonec commented Nov 30, 2020

@Tratcher can you please review this PR. It is slightly related to previous huffman PR, but considerable simpler and safer changes.

@Tratcher
Copy link
Member

@Tratcher can you please review this PR. It is slightly related to previous huffman PR, but considerable simpler and safer changes.

Not immediately, I'm dealing with builds for the next two days.

@rokonec
Copy link
Contributor Author

rokonec commented Dec 3, 2020

@Tratcher, @halter73 Can any of you please review this PR. This one is really simple.

@Tratcher Tratcher self-requested a review December 4, 2020 20:19
Copy link
Member

@Tratcher Tratcher left a comment

Choose a reason for hiding this comment

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

wait, this is how much better? 😆

@rokonec rokonec merged commit c2404a9 into dotnet:master Dec 4, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 3, 2021
@karelz karelz added this to the 6.0.0 milestone Jan 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants