Skip to content

Commit 645e39b

Browse files
authored
DryIOC JIT optimizations. (#5370)
This fixes a specific codepath which was not optimized. this is saving ~50msec in JIT time during cold start.
1 parent c6f6ecb commit 645e39b

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/WebJobs.Script.WebHost/DependencyInjection/DryIoc/Container.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ namespace DryIoc
6464
using MemberAssignmentExpr = System.Linq.Expressions.MemberAssignment;
6565
using FactoryDelegateExpr = System.Linq.Expressions.Expression<FactoryDelegate>;
6666
using global::Microsoft.Azure.WebJobs.Script.WebHost.DependencyInjection.DryIoc;
67-
6867
#endif
6968

7069
/// <summary>IoC Container. Documentation is available at https://bitbucket.org/dadhi/dryioc. </summary>
@@ -432,11 +431,11 @@ private void ThrowIfContainerDisposed()
432431
_scopeContext == null ? _ownCurrentScope : _scopeContext.GetCurrentOrDefault();
433432

434433
/// <inheritdoc />
435-
public IResolverContext WithCurrentScope(IScope scope)
434+
public IResolverContext WithCurrentScope(IScope scope, bool preferInterpretaion = false)
436435
{
437436
ThrowIfContainerDisposed();
438437
return new Container(Rules, _registry, _singletonScope, _scopeContext,
439-
scope, _disposed, _disposeStackTrace, parent: this, root: _root ?? this);
438+
scope, _disposed, _disposeStackTrace, parent: this, root: _root ?? this, preferInterpretation: preferInterpretaion);
440439
}
441440

442441
void IResolverContext.UseInstance(Type serviceType, object instance, IfAlreadyRegistered ifAlreadyRegistered,
@@ -693,7 +692,7 @@ public IContainer With(Rules rules, IScopeContext scopeContext, RegistrySharing
693692
: Ref.Of(_registry.Value.WithoutCache());
694693

695694
return new Container(rules, registry, singletonScope, scopeContext,
696-
_ownCurrentScope, _disposed, _disposeStackTrace, _parent, _root);
695+
_ownCurrentScope, _disposed, _disposeStackTrace, _parent, _root, _preferInterpretation);
697696
}
698697

699698
/// <summary>Produces new container which prevents any further registrations.</summary>
@@ -2593,7 +2592,7 @@ public interface IResolverContext : IResolver, IDisposable
25932592
IScope CurrentScope { get; }
25942593

25952594
/// <summary>Creates resolver context with specified current scope (or container which implements the context).</summary>
2596-
IResolverContext WithCurrentScope(IScope scope);
2595+
IResolverContext WithCurrentScope(IScope scope, bool preferInterpretation);
25972596

25982597
/// <summary>Allows to put instance into the scope.</summary>
25992598
void UseInstance(Type serviceType, object instance, IfAlreadyRegistered IfAlreadyRegistered,
@@ -2687,7 +2686,7 @@ public static IScope GetNamedScope(this IResolverContext r, object name, bool th
26872686
/// handler.Handle(data);
26882687
/// }
26892688
/// ]]></code></example>
2690-
public static IResolverContext OpenScope(this IResolverContext r, object name = null, bool trackInParent = false)
2689+
public static IResolverContext OpenScope(this IResolverContext r, object name = null, bool trackInParent = false, bool preferInterpretation = false)
26912690
{
26922691
// todo: Should we use OwnCurrentScope, then should it be in ResolverContext?
26932692
var openedScope = r.ScopeContext == null
@@ -2697,7 +2696,7 @@ public static IResolverContext OpenScope(this IResolverContext r, object name =
26972696
if (trackInParent)
26982697
(openedScope.Parent ?? r.SingletonScope).TrackDisposable(openedScope);
26992698

2700-
return r.WithCurrentScope(openedScope);
2699+
return r.WithCurrentScope(openedScope, preferInterpretation);
27012700
}
27022701
}
27032702

src/WebJobs.Script.WebHost/DependencyInjection/ScopedResolver.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public void Dispose()
4040
internal ServiceScope CreateChildScope(IServiceScopeFactory rootScopeFactory)
4141
{
4242
var scopedRoot = rootScopeFactory.CreateScope();
43-
Container scopedContext = Container.OpenScope() as Container;
43+
var preferInterpretation = (Container as Container).PreferInterpretation;
44+
Container scopedContext = Container.OpenScope(preferInterpretation: preferInterpretation) as Container;
4445

4546
Rules rules = scopedContext.Rules;
4647
foreach (var unknownServiceResolver in scopedContext.Rules.UnknownServiceResolvers)

src/WebJobs.Script.WebHost/DependencyInjection/WebHostServiceProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public object GetService(Type serviceType)
4848

4949
public IServiceScope CreateScope()
5050
{
51-
return new JobHostServiceScope(_container.OpenScope());
51+
return new JobHostServiceScope(_container.OpenScope(preferInterpretation: _container.PreferInterpretation));
5252
}
5353
}
5454
}

0 commit comments

Comments
 (0)