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

feat: Use IEnumerable in WriteApi to eliminate unnecessary memory allocations #606

Closed

Conversation

birdalicious
Copy link

@birdalicious birdalicious commented Jan 17, 2024

Proposed Changes

Change WriteApi to use IEnumerable for collection arguments instead of List.
Change WriteRecords(List<string> records) to WriteRecords(IEnumerable<string> records)

Calling ToList on a collection will incur a memory allocation as the data is copied to the new list. Making the argument IEnumerable means ToList doesn't need to be called and so no extra memory allocation.
Internally this will eliminate the unnecessary memory allocation in WriteRecords(string[] record) call to ToList, and client code also won't have to make the allocation if their data isn't already in a List## Checklist

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • dotnet test completes successfully
  • Commit messages are conventional
  • Sign CLA (if not already signed)

@birdalicious birdalicious changed the title Use IEnumerable in WriteApi to elimiate unnecssary memory allocations Use IEnumerable in WriteApi to eliminate unnecessary memory allocations Jan 17, 2024
@bednar bednar changed the title Use IEnumerable in WriteApi to eliminate unnecessary memory allocations feat: Use IEnumerable in WriteApi to eliminate unnecessary memory allocations Jan 18, 2024
Copy link
Contributor

@bednar bednar left a comment

Choose a reason for hiding this comment

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

@birdalicious thanks for your PR 👍

Please satisfy our Checklist after that we are be able to approve this PR:

image

@birdalicious birdalicious force-pushed the ienumerable-writeapi branch 2 times, most recently from df800f2 to 29eed6e Compare January 22, 2024 08:40
@birdalicious
Copy link
Author

What do I need to run dotnet test I've installed all the versions of .NET required but what is the setup up for the influx instances on 8086/9999?

@bednar
Copy link
Contributor

bednar commented Jan 22, 2024

You can start pre-configured InfluxDB instances in a Docker environment using the /Scripts/influxdb-restart.sh script.

@@ -220,7 +220,7 @@ public class WriteApiAsync : IWriteApiAsync
public Task WriteRecordsAsync(string[] records, WritePrecision precision = WritePrecision.Ns,
string bucket = null, string org = null, CancellationToken cancellationToken = default)
{
return WriteRecordsAsync(records.ToList(), precision, bucket, org, cancellationToken);
return WriteRecordsAsync(records, precision, bucket, org, cancellationToken);
Copy link
Contributor

Choose a reason for hiding this comment

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

This causes infinity recursive, please change to:

Suggested change
return WriteRecordsAsync(records, precision, bucket, org, cancellationToken);
return WriteRecordsAsync((IEnumerable<string>)records, precision, bucket, org, cancellationToken);

@@ -294,7 +293,7 @@ await WriteData(options.OrganizationId, options.Bucket, grouped.Key, groupedPoin
public Task WritePointsAsync(PointData[] points, string bucket = null, string org = null,
CancellationToken cancellationToken = default)
{
return WritePointsAsync(points.ToList(), bucket, org, cancellationToken);
return WritePointsAsync(points, bucket, org, cancellationToken);
Copy link
Contributor

Choose a reason for hiding this comment

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

This causes infinity recursive, please change to:

Suggested change
return WritePointsAsync(points, bucket, org, cancellationToken);
return WritePointsAsync((IEnumerable<PointData>)points, bucket, org, cancellationToken);

@@ -380,7 +379,7 @@ await WriteData(options.OrganizationId, options.Bucket, grouped.Key, groupedPoin
public Task WriteMeasurementsAsync<TM>(TM[] measurements, WritePrecision precision = WritePrecision.Ns,
string bucket = null, string org = null, CancellationToken cancellationToken = default)
{
return WriteMeasurementsAsync(measurements.ToList(), precision, bucket, org, cancellationToken);
return WriteMeasurementsAsync(measurements, precision, bucket, org, cancellationToken);
Copy link
Contributor

Choose a reason for hiding this comment

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

This causes infinity recursive, please change to:

Suggested change
return WriteMeasurementsAsync(measurements, precision, bucket, org, cancellationToken);
return WriteMeasurementsAsync((IEnumerable<TM>)measurements, precision, bucket, org, cancellationToken);

@bednar
Copy link
Contributor

bednar commented Feb 1, 2024

This PR has been closed because it has not had recent activity. Please reopen if this PR is still important to you and you want to continue with them.

@bednar bednar closed this Feb 1, 2024
@bednar bednar added the invalid This doesn't seem right label Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants