-
Notifications
You must be signed in to change notification settings - Fork 94
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
Conversation
There was a problem hiding this 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:
df800f2
to
29eed6e
Compare
What do I need to run |
You can start pre-configured InfluxDB instances in a Docker environment using the |
29eed6e
to
9d8b7ff
Compare
@@ -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); |
There was a problem hiding this comment.
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:
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); |
There was a problem hiding this comment.
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:
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); |
There was a problem hiding this comment.
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:
return WriteMeasurementsAsync(measurements, precision, bucket, org, cancellationToken); | |
return WriteMeasurementsAsync((IEnumerable<TM>)measurements, precision, bucket, org, cancellationToken); |
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. |
Proposed Changes
Change WriteApi to use IEnumerable for collection arguments instead of List.
Change
WriteRecords(List<string> records)
toWriteRecords(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## ChecklistChecklist
dotnet test
completes successfully