Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Cuckoo metadata#24498

Merged
davidwrighton merged 20 commits into
dotnet:masterfrom
davidwrighton:cuckoo_metadata
May 20, 2019
Merged

Cuckoo metadata#24498
davidwrighton merged 20 commits into
dotnet:masterfrom
davidwrighton:cuckoo_metadata

Conversation

@davidwrighton

Copy link
Copy Markdown
Member

Replace attribute reading code with possibly higher performance path that uses a r2r generated cuckoo filter instead of searching CustomAttribute table.

  • Performance not yet fully investigated. Will finalize that before asking for review.

- Implement cuckoo filter lookup logic
- Implement new ready to run section
 - Add dumper to R2RDump
 - Parse section on load into data structure
 - Implement function to query filter
- Add concept of enum of well known attributes
  - So that attribute name hashes themselves may be cached
This should fix the current error seen when compiling on Linux. The OSX issue with immintrin.h will be dealt with later.
@tannergooding

Copy link
Copy Markdown
Member

Performance not yet fully investigated. Will finalize that before asking for review.

Are you going to use the nullable annotated S.P.Corelib as one of the tests?

#ifndef __WELLKNOWNATTRIBUTES_H_
#define __WELLKNOWNATTRIBUTES_H_

enum class WellKnownAttribute : DWORD

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is only attributes that the VM/JIT cares about, correct?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

At the moment. Yeah, its most of the ones the VM/JIT cares about. @sebastienros suggested I look into ASP.NET startup and see if I should see if I thought this might be useful to improve attribute query perf for managed code too.

@davidwrighton

Copy link
Copy Markdown
Member Author

Performance not yet fully investigated. Will finalize that before asking for review.

Are you going to use the nullable annotated S.P.Corelib as one of the tests?

@tannergooding The tests I am looking at are small process start tests, which are primarily impacted by S.P.Corelib type load perf, so yeah, its the primary test vehicle. I need to find out if there is a threshold for which doing the hashing calculation is just more expensive than the table scan, but I suspect it will work quite well.

@tannergooding do you have a reference for the right way to detect if I can use ARM NEON instructions on Windows/Linux? With the current implementation, I'm not very optimistic about performance without the SIMD based comparison, so my preference would be to generate the optimized table unconditionally, but only use it if SIMD instructions are available for use.

@tannergooding

tannergooding commented May 10, 2019

Copy link
Copy Markdown
Member

do you have a reference for the right way to detect if I can use ARM NEON instructions on Windows/Linux?

We have some existing code in the VM utilizing IsProcessorFeaturePresent and some flags to try and detect this. However, we also just assume NEON/AdvSIMD is supported for ARM/ARM64.

You can see where we set the JIT flags and do other ISA checks for ARM/ARM64 here: https://github.com/dotnet/coreclr/blob/master/src/vm/codeman.cpp#L1481

It's also worth noting that Windows doesn't currently expose all the same ISA flags for ARM as Linux does, which goes through PAL_GetJitCpuCapabilityFlags instead.

@jkotas

jkotas commented May 10, 2019

Copy link
Copy Markdown
Member

With the current implementation, I'm not very optimistic about performance without the SIMD based comparison,

My guess is that the performance without SIMD would be just fine. The copy of the SIMD header looks like a maintenance nightmare...

@davidwrighton

Copy link
Copy Markdown
Member Author

The SIMD header is deeply dissatisfying, however, I expect maintenance to be minimal. We've already been maintaining a very similar SIMD header for some SSE intrinsics in xmmintrin.h without much ongoing cost. I'll want to investigate the performance here before I make any judgements here though.

- With current xor based second hash system, cuckoo filters must be powers of two. This can be addressed later, after performance is analyzed.
- Probably doesn't work on *nix platforms, but I'll discover that in the
cloud
Comment thread src/vm/nativeformatreader.h Outdated

#ifndef DACCESS_COMPILE

#if defined(_M_X64) || defined(__x86_64__) || defined(__i386__) || defined(_M_IX86)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you please use _TARGET_AMD64_ / _TARGET_X86_ / _TARGET_ARM_ / _TARGET_ARM64_ instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, because these aren't about the target architecture. They are about the compilation architecture. I could not find a set of compilation architecture #defines to use.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, right. Then you can use _ARM_, _ARM64_, _X86_ and _AMD64_


/*

The below hash combining function is based on the xxHash32 logic implemented

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems we should put the license into THIRD-PARTY-NOTICES.TXT too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Its already in there. See License notice for xxHash.

- Our build environments aren't setup for NEON intrinsics
- Performance win is affected by using non-SIMD path, but the cuckoo filter is still an overall win. Once this is all checked in, I'll open an issue to enable SIMD in our build.
- Fix the disable filter logic
- Disable the presence table for non Corelib cases. Current performance data does not warrant the size increase in other generated binaries
@davidwrighton

Copy link
Copy Markdown
Member Author

The performance improvement seems to be limited to coreLib, so I've restricted the implementation to be Corelib only to avoid excess bloat in R2R images. This is disappointing, but not surprising, as corelib has types loaded and referenced from it at rates which far exceed that of other dlls. As we put together more startup measurement data, we should revisit this policy.

@davidwrighton davidwrighton changed the title [WIP]Cuckoo metadata Cuckoo metadata May 17, 2019
@davidwrighton davidwrighton marked this pull request as ready for review May 17, 2019 01:41
…o_metadata

Attempted to address conflict with native type parsing
Comment thread src/vm/readytoruninfo.cpp Outdated
}

// For format version 3.1 and later, there is an optional attributes section
if (IsImageVersionAtLeast(3,1))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: I know that you are following the existing pattern, but these IsImageVersionAtLeast checks are unnecessary. (I think I have made the same comment the last time new structure got added here.)

@jkotas

jkotas commented May 17, 2019

Copy link
Copy Markdown
Member

Build breaks:

/__w/1/s/src/zap/../vm/nativeformatreader.h:24:10: fatal error: 'arm64_neon.h' file not found
#include "arm64_neon.h"

@sergiy-k

Copy link
Copy Markdown

What else needs to be done here before this PR can be merged?

@janvorli janvorli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, I only found a small nit that you may ignore.

Comment thread src/vm/assembly.hpp
if (!IsWinMD()) // ignore classic COM interop CAs in .winmd
{
if (this->GetManifestImport()->GetCustomAttributeByName(TokenFromRid(1, mdtAssembly), INTEROP_IMPORTEDFROMTYPELIB_TYPE, 0, 0) == S_OK)
if (GetManifestModule()->GetCustomAttribute(TokenFromRid(1, mdtAssembly), WellKnownAttribute::ImportedFromTypeLib, NULL, 0) == S_OK)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A nit - maybe we can use the Assembly::GetCustomAttribute wrapper here to make the line little less verbose. The same for the occurrence in the assembly.cpp above.

@davidwrighton davidwrighton merged commit adecd85 into dotnet:master May 20, 2019
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Basic infra for cuckoo filter of attributes
- Implement cuckoo filter lookup logic
- Implement new ready to run section
 - Add dumper to R2RDump
 - Parse section on load into data structure
 - Implement function to query filter
- Add concept of enum of well known attributes
  - So that attribute name hashes themselves may be cached
* Wrap all even vaguely perf critical uses of attribute by name parsing with use of R2R data
* Update emmintrin.h in the PAL header to contain the needed SSE2 intrinsics for the feature
- Disable the presence table for non Corelib cases. Current performance data does not warrant the size increase in other generated binaries

Commit migrated from dotnet/coreclr@adecd85
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants