Skip to content

Commit

Permalink
Added missing ValueTask (non-generic) to InProcess (no emit) toolchains.
Browse files Browse the repository at this point in the history
  • Loading branch information
timcassell committed Jan 2, 2023
1 parent 68e4459 commit 4d2a07a
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ private static BenchmarkAction CreateCore(
if (resultType == typeof(Task))
return new BenchmarkActionTask(resultInstance, targetMethod, unrollFactor);

if (resultType == typeof(ValueTask))
return new BenchmarkActionValueTask(resultInstance, targetMethod, unrollFactor);

if (resultType.GetTypeInfo().IsGenericType)
{
var genericType = resultType.GetGenericTypeDefinition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,45 @@ private void InvokeMultipleHardcoded(long repeatCount)
public override object LastRunResult => result;
}

internal class BenchmarkActionValueTask : BenchmarkActionBase
{
private readonly Func<ValueTask> startTaskCallback;
private readonly Action callback;
private readonly Action unrolledCallback;

public BenchmarkActionValueTask(object instance, MethodInfo method, int unrollFactor)
{
bool isIdle = method == null;
if (!isIdle)
{
startTaskCallback = CreateWorkload<Func<ValueTask>>(instance, method);
callback = ExecuteBlocking;
}
else
{
callback = Overhead;
}

InvokeSingle = callback;

unrolledCallback = Unroll(callback, unrollFactor);
InvokeMultiple = InvokeMultipleHardcoded;

}

// must be kept in sync with VoidDeclarationsProvider.IdleImplementation
private void Overhead() { }

// must be kept in sync with TaskDeclarationsProvider.TargetMethodDelegate
private void ExecuteBlocking() => Helpers.AwaitHelper.GetResult(startTaskCallback.Invoke());

private void InvokeMultipleHardcoded(long repeatCount)
{
for (long i = 0; i < repeatCount; i++)
unrolledCallback();
}
}

internal class BenchmarkActionValueTask<T> : BenchmarkActionBase
{
private readonly Func<ValueTask<T>> startTaskCallback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ private static BenchmarkAction CreateCore(
if (resultType == typeof(Task))
return new BenchmarkActionTask(resultInstance, targetMethod, codegenMode, unrollFactor);

if (resultType == typeof(ValueTask))
return new BenchmarkActionValueTask(resultInstance, targetMethod, codegenMode, unrollFactor);

if (resultType.GetTypeInfo().IsGenericType)
{
var genericType = resultType.GetGenericTypeDefinition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,51 @@ private void InvokeMultipleHardcoded(long repeatCount)
public override object LastRunResult => result;
}

internal class BenchmarkActionValueTask : BenchmarkActionBase
{
private readonly Func<ValueTask> startTaskCallback;
private readonly Action callback;
private readonly Action unrolledCallback;

public BenchmarkActionValueTask(object instance, MethodInfo method, BenchmarkActionCodegen codegenMode, int unrollFactor)
{
bool isIdle = method == null;
if (!isIdle)
{
startTaskCallback = CreateWorkload<Func<ValueTask>>(instance, method);
callback = ExecuteBlocking;
}
else
{
callback = Overhead;
}

InvokeSingle = callback;

if (UseFallbackCode(codegenMode, unrollFactor))
{
unrolledCallback = Unroll(callback, unrollFactor);
InvokeMultiple = InvokeMultipleHardcoded;
}
else
{
InvokeMultiple = EmitInvokeMultiple(this, nameof(callback), null, unrollFactor);
}
}

// must be kept in sync with VoidDeclarationsProvider.IdleImplementation
private void Overhead() { }

// must be kept in sync with TaskDeclarationsProvider.TargetMethodDelegate
private void ExecuteBlocking() => Helpers.AwaitHelper.GetResult(startTaskCallback.Invoke());

private void InvokeMultipleHardcoded(long repeatCount)
{
for (long i = 0; i < repeatCount; i++)
unrolledCallback();
}
}

internal class BenchmarkActionValueTask<T> : BenchmarkActionBase
{
private readonly Func<ValueTask<T>> startTaskCallback;
Expand Down
Loading

0 comments on commit 4d2a07a

Please sign in to comment.