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

Add "cache add" functionality to project caching - Attempt 2 #9214

Merged
merged 15 commits into from
Sep 19, 2023

Conversation

dfederm
Copy link
Contributor

@dfederm dfederm commented Sep 11, 2023

This is a redo of #8726, but with fixes to make the changes acceptable for VS insertion.

ManualResetEventSlim handle = _fileAccessCompletionWaitHandles.GetOrAdd(globalRequestId, static _ => new ManualResetEventSlim());
handle.Set();
}
else if (_tempDirectory != null && fileAccessPath.StartsWith(_tempDirectory))
Copy link
Member

Choose a reason for hiding this comment

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

This StartsWith is culture specific while the previous one is ordinal.

/// </summary>
/// <param name="fileAccessData">The file access to report.</param>
[CLSCompliant(false)]
public virtual void ReportFileAccess(FileAccessData fileAccessData) => throw new NotImplementedException();
Copy link
Member

Choose a reason for hiding this comment

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

Did you consider making this parameter in FileAccessData? This is a 9 member struct which means every call to this API is going to involve a lot of copies. This API is going to be called a lot in a tight loop for non-trivial build operations so it's one where efficiency may be important.

Handlers[] localHandlers = _handlers;
foreach (Handlers handlers in localHandlers)
{
handlers.FileAccessHander.Invoke(buildRequest, fileAccessData);
Copy link
Member

Choose a reason for hiding this comment

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

This is another case where we're copying a large struct in a loop (this is nested in another loop so even more copies).

/// <inheritdoc/>
public void Translate(ITranslator translator) => translator.Translate(ref _fileAccessData);

internal FileAccessData FileAccessData => _fileAccessData;
Copy link
Member

Choose a reason for hiding this comment

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

This is a place you should consider using

intenal ref readonly FileAccessData FileAccessData => ref _fileAccessData;

Otherwise you're doing a full copy just to access one or two members.

{
private FileAccessData _fileAccessData;

internal FileAccessReport(FileAccessData fileAccessData) => _fileAccessData = fileAccessData;
Copy link
Member

Choose a reason for hiding this comment

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

Another place to consider in FileAccessData

/// Called for each file access from an MSBuild node or one of its children.
/// </summary>
[CLSCompliant(false)]
public virtual void HandleFileAccess(FileAccessContext fileAccessContext, FileAccessData fileAccessData)
Copy link
Member

Choose a reason for hiding this comment

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

Can use in here

/// Called for each new child process created by an MSBuild node or one of its children.
/// </summary>
[CLSCompliant(false)]
public virtual void HandleProcess(FileAccessContext fileAccessContext, ProcessData processData)
Copy link
Member

Choose a reason for hiding this comment

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

Can use in here

/// <inheritdoc/>
public NodePacketType Type => NodePacketType.ProcessReport;

internal ProcessData ProcessData => _processData;
Copy link
Member

Choose a reason for hiding this comment

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

A place where you can use ref readonly to alleviate copies

internal ref readonly ProcessData ProcessData => ref _processData;

{
private ProcessData _processData;

internal ProcessReport(ProcessData processData) => _processData = processData;
Copy link
Member

Choose a reason for hiding this comment

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

can use in here

Handlers[] localHandlers = _handlers;
foreach (Handlers handlers in localHandlers)
{
handlers.ProcessHandler.Invoke(buildRequest, processData);
Copy link
Member

Choose a reason for hiding this comment

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

Copying a large struct in a loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants