Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,7 @@ private void GenerateSectionSeparator(TextWriter writer)

PrivateData = @{{
ImplicitRemoting = $true
ImplicitSessionId = '{4}'
}}
}}
";
Expand All @@ -2003,7 +2004,8 @@ private void GenerateManifest(TextWriter writer, string psm1fileName, string for
CodeGeneration.EscapeSingleQuotedStringContent(_moduleGuid.ToString()),
CodeGeneration.EscapeSingleQuotedStringContent(StringUtil.Format(ImplicitRemotingStrings.ProxyModuleDescription, this.GetConnectionString())),
CodeGeneration.EscapeSingleQuotedStringContent(Path.GetFileName(psm1fileName)),
CodeGeneration.EscapeSingleQuotedStringContent(Path.GetFileName(formatPs1xmlFileName)));
CodeGeneration.EscapeSingleQuotedStringContent(Path.GetFileName(formatPs1xmlFileName)),
this._remoteRunspaceInfo.InstanceId);
}

#endregion
Expand Down
18 changes: 18 additions & 0 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Management.Automation.Language;

using Dbg = System.Management.Automation.Diagnostics;

Expand Down Expand Up @@ -320,6 +322,22 @@ internal Collection<PSObject> ExecuteCommand(string command, out Exception excep
{
Dbg.Assert(!String.IsNullOrEmpty(command), "command should have a value");

// Experimental:
// Check for implicit remoting commands that can be batched, and execute as batched if able.
if (ExperimentalFeature.IsEnabled("PSImplicitRemotingBatching"))
{
var addOutputter = ((options & ExecutionOptions.AddOutputter) > 0);
if (addOutputter &&
!_parent.RunspaceRef.IsRunspaceOverridden &&
_parent.RunspaceRef.Runspace.ExecutionContext.Modules != null &&
_parent.RunspaceRef.Runspace.ExecutionContext.Modules.IsImplicitRemotingModuleLoaded &&
Utils.TryRunAsImplicitBatch(command, _parent.RunspaceRef.Runspace))
{
exceptionThrown = null;
return null;
}
}

Pipeline tempPipeline = CreatePipeline(command, (options & ExecutionOptions.AddToHistory) > 0);

return ExecuteCommandHelper(tempPipeline, out exceptionThrown, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ static ExperimentalFeature()
source: EngineSource,
isEnabled: false),
*/
new ExperimentalFeature(name: "PSImplicitRemotingBatching",
description: "Batch implicit remoting proxy commands to improve performance",
source: EngineSource,
isEnabled: false)
};
EngineExperimentalFeatures = new ReadOnlyCollection<ExperimentalFeature>(engineFeatures);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5034,6 +5034,21 @@ internal void RemoveModule(PSModuleInfo module, string moduleNameInRemoveModuleC

// And the appdomain level module path cache.
PSModuleInfo.RemoveFromAppDomainLevelCache(module.Name);

// Update implicit module loaded property
if (Context.Modules.IsImplicitRemotingModuleLoaded)
{
Context.Modules.IsImplicitRemotingModuleLoaded = false;
foreach (var modInfo in Context.Modules.ModuleTable.Values)
{
var privateData = modInfo.PrivateData as Hashtable;
if ((privateData != null) && privateData.ContainsKey("ImplicitRemoting"))
{
Context.Modules.IsImplicitRemotingModuleLoaded = true;
break;
}
}
}
}
}
}
Expand Down Expand Up @@ -6883,6 +6898,13 @@ internal static void AddModuleToModuleTables(ExecutionContext context, SessionSt
{
targetSessionState.Module.AddNestedModule(module);
}

var privateDataHashTable = module.PrivateData as Hashtable;
if (context.Modules.IsImplicitRemotingModuleLoaded == false &&
privateDataHashTable != null && privateDataHashTable.ContainsKey("ImplicitRemoting"))
{
context.Modules.IsImplicitRemotingModuleLoaded = true;
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ internal ModuleIntrinsics(ExecutionContext context)

private const int MaxModuleNestingDepth = 10;

/// <summary>
/// Gets and sets boolean that indicates when an implicit remoting module is loaded.
/// </summary>
internal bool IsImplicitRemotingModuleLoaded
{
get;
set;
}

internal void IncrementModuleNestingDepth(PSCmdlet cmdlet, string path)
{
if (++ModuleNestingDepth > MaxModuleNestingDepth)
Expand Down
Loading