Skip to content

Significant performance issue with the driver running under .NET Framework #8775

@onyxmaster

Description

@onyxmaster

Elastic.Clients.Elasticsearch version:
8.19.12

Elasticsearch version:
Irrelevant

.NET runtime version:
4.7.2 TFM, 4.8.1 runtime

Operating system version:
Windows 11

Description of the problem including expected versus actual behavior:
The Enum.HasFlag under .NET Framework boxes its argument leading to excessive allocations on hot paths. While in modern .NET this issue is not present, the classic behavior is, unfortunately, as described.
When HasFlag is used casually (in composition code or request setup) it could be okay, but when it's used in tight loops like serialization code, it brings a lot of unnecessary allocations (we measured about 6M objects per 30s in our specific scenario since we index embedding vectors which employs floating-point serialization extensively) significantly increasing pressure for gen0 allocations/collections.

I did a search over the codebase and HasFlag is only used in three distinct source files (1, 2, 3), so it does not look like it's a common practice, hence the improvement looks low-effort for me.

I can provide a PR for the first two files, replacing HasFlag calls with generic bit checks (value & flag) == flag, but not sure what to do with the generated code.

Thanks for taking a look.

P.S. PerfView traces are available upon request

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions