-
Notifications
You must be signed in to change notification settings - Fork 437
Add source generator for UnbindAllBindables #5764
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
Open
smoogipoo
wants to merge
10
commits into
ppy:master
Choose a base branch
from
smoogipoo:unbind-bindables-sgen
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
884ef84
Add source generator for UnbindAllBindables
smoogipoo 28beadc
Support auto properties and explicit implementations
smoogipoo a0d3b3b
Exclude statics
smoogipoo 9ac6e5c
Support nullability
smoogipoo 5cf556b
Add helper method
smoogipoo 89e821a
Extract common name to const
smoogipoo 72d5f32
Rename method
smoogipoo 42b43fb
Actually elide reflection pathway
smoogipoo a5c7c73
Add complex unbind benchmark
smoogipoo f523462
Merge branch 'master' into unbind-bindables-sgen
bdach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...Resources/UnbindAllBindables/AutoProperty/Generated/g_AutoProperty_UnbindAllBindables.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// <auto-generated/> | ||
#nullable enable | ||
#pragma warning disable CS4014 | ||
|
||
partial class AutoProperty : global::osu.Framework.Graphics.ISourceGeneratedUnbindAllBindables | ||
{ | ||
global::System.Type global::osu.Framework.Graphics.ISourceGeneratedUnbindAllBindables.KnownType => typeof(global::AutoProperty); | ||
public override void InternalUnbindAllBindables() | ||
{ | ||
base.InternalUnbindAllBindables(); | ||
global::osu.Framework.Utils.SourceGeneratorUtils.UnbindBindable(typeof(global::AutoProperty), ((global::AutoProperty)this).Bindable1); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...SourceGeneration.Tests/Resources/UnbindAllBindables/AutoProperty/Sources/AutoProperty.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public partial class AutoProperty : osu.Framework.Graphics.Drawable | ||
{ | ||
private osu.Framework.Bindables.Bindable<int> Bindable1 { get; set; } = new osu.Framework.Bindables.Bindable<int>(); | ||
} |
13 changes: 13 additions & 0 deletions
13
...tion.Tests/Resources/UnbindAllBindables/Basic/Generated/g_BaseType_UnbindAllBindables.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// <auto-generated/> | ||
#nullable enable | ||
#pragma warning disable CS4014 | ||
|
||
partial class BaseType : global::osu.Framework.Graphics.ISourceGeneratedUnbindAllBindables | ||
{ | ||
global::System.Type global::osu.Framework.Graphics.ISourceGeneratedUnbindAllBindables.KnownType => typeof(global::BaseType); | ||
public override void InternalUnbindAllBindables() | ||
{ | ||
base.InternalUnbindAllBindables(); | ||
global::osu.Framework.Utils.SourceGeneratorUtils.UnbindBindable(typeof(global::BaseType), ((global::BaseType)this).Bindable1); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...n.Tests/Resources/UnbindAllBindables/Basic/Generated/g_DerivedType_UnbindAllBindables.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// <auto-generated/> | ||
#nullable enable | ||
#pragma warning disable CS4014 | ||
|
||
partial class DerivedType : global::osu.Framework.Graphics.ISourceGeneratedUnbindAllBindables | ||
{ | ||
global::System.Type global::osu.Framework.Graphics.ISourceGeneratedUnbindAllBindables.KnownType => typeof(global::DerivedType); | ||
public override void InternalUnbindAllBindables() | ||
{ | ||
base.InternalUnbindAllBindables(); | ||
global::osu.Framework.Utils.SourceGeneratorUtils.UnbindBindable(typeof(global::DerivedType), ((global::DerivedType)this).Bindable2); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
osu.Framework.SourceGeneration.Tests/Resources/UnbindAllBindables/Basic/Sources/BaseType.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public partial class BaseType : osu.Framework.Graphics.Drawable | ||
{ | ||
private readonly osu.Framework.Bindables.Bindable<int> Bindable1 = new osu.Framework.Bindables.Bindable<int>(); | ||
} |
4 changes: 4 additions & 0 deletions
4
...amework.SourceGeneration.Tests/Resources/UnbindAllBindables/Basic/Sources/DerivedType.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public partial class DerivedType : BaseType | ||
{ | ||
private readonly osu.Framework.Bindables.Bindable<int> Bindable2 = new osu.Framework.Bindables.Bindable<int>(); | ||
} |
14 changes: 14 additions & 0 deletions
14
...bindAllBindables/CommonGenerated/g_osu.Framework.Graphics.Drawable_UnbindAllBindables.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// <auto-generated/> | ||
#nullable enable | ||
#pragma warning disable CS4014 | ||
|
||
namespace osu.Framework.Graphics | ||
{ | ||
partial class Drawable : global::osu.Framework.Graphics.ISourceGeneratedUnbindAllBindables | ||
{ | ||
global::System.Type global::osu.Framework.Graphics.ISourceGeneratedUnbindAllBindables.KnownType => typeof(global::osu.Framework.Graphics.Drawable); | ||
public virtual void InternalUnbindAllBindables() | ||
{ | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
osu.Framework.SourceGeneration.Tests/Resources/UnbindAllBindables/CommonSources/Bindable.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace osu.Framework.Bindables | ||
{ | ||
public interface IUnbindable | ||
{ | ||
void UnbindAll(); | ||
} | ||
|
||
public interface IBindable : IUnbindable | ||
{ | ||
} | ||
|
||
public interface IBindable<T> : IBindable | ||
{ | ||
} | ||
|
||
public class Bindable<T> : IBindable<T> | ||
{ | ||
public void UnbindAll() | ||
{ | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
osu.Framework.SourceGeneration.Tests/Resources/UnbindAllBindables/CommonSources/Drawable.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace osu.Framework.Graphics | ||
{ | ||
public partial class Drawable | ||
{ | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...n.Tests/Resources/UnbindAllBindables/CommonSources/ISourceGeneratedUnbindAllBindables.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace osu.Framework.Graphics | ||
{ | ||
public interface ISourceGeneratedUnbindAllBindables | ||
{ | ||
System.Type KnownType { get; } | ||
|
||
void InternalUnbindAllBindables(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ourceGeneration.Tests/Resources/UnbindAllBindables/CommonSources/SourceGeneratorUtils.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#nullable enable | ||
|
||
namespace osu.Framework.Utils | ||
{ | ||
public static class SourceGeneratorUtils | ||
{ | ||
public static void UnbindBindable(System.Type containingType, osu.Framework.Bindables.IUnbindable? bindable) | ||
{ | ||
} | ||
} | ||
} | ||
|
||
#nullable disable |
13 changes: 13 additions & 0 deletions
13
...indables/ExplicitImplementation/Generated/g_ExplicitImplementation_UnbindAllBindables.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// <auto-generated/> | ||
#nullable enable | ||
#pragma warning disable CS4014 | ||
|
||
partial class ExplicitImplementation : global::osu.Framework.Graphics.ISourceGeneratedUnbindAllBindables | ||
{ | ||
global::System.Type global::osu.Framework.Graphics.ISourceGeneratedUnbindAllBindables.KnownType => typeof(global::ExplicitImplementation); | ||
public override void InternalUnbindAllBindables() | ||
{ | ||
base.InternalUnbindAllBindables(); | ||
global::osu.Framework.Utils.SourceGeneratorUtils.UnbindBindable(typeof(global::ExplicitImplementation), ((ITestInterface)this).Bindable1); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ts/Resources/UnbindAllBindables/ExplicitImplementation/Sources/ExplicitImplementation.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public partial class ExplicitImplementation : osu.Framework.Graphics.Drawable, ITestInterface | ||
{ | ||
osu.Framework.Bindables.Bindable<int> ITestInterface.Bindable1 { get; } = new osu.Framework.Bindables.Bindable<int>(); | ||
} | ||
|
||
public interface ITestInterface | ||
{ | ||
osu.Framework.Bindables.Bindable<int> Bindable1 { get; } | ||
} |
13 changes: 13 additions & 0 deletions
13
...n.Tests/Resources/UnbindAllBindables/Nullable/Generated/g_Nullable_UnbindAllBindables.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// <auto-generated/> | ||
#nullable enable | ||
#pragma warning disable CS4014 | ||
|
||
partial class Nullable : global::osu.Framework.Graphics.ISourceGeneratedUnbindAllBindables | ||
{ | ||
global::System.Type global::osu.Framework.Graphics.ISourceGeneratedUnbindAllBindables.KnownType => typeof(global::Nullable); | ||
public override void InternalUnbindAllBindables() | ||
{ | ||
base.InternalUnbindAllBindables(); | ||
global::osu.Framework.Utils.SourceGeneratorUtils.UnbindBindable(typeof(global::Nullable), ((global::Nullable)this).Bindable1); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...amework.SourceGeneration.Tests/Resources/UnbindAllBindables/Nullable/Sources/Nullable.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public partial class Nullable : osu.Framework.Graphics.Drawable | ||
{ | ||
public osu.Framework.Bindables.Bindable<int>? Bindable1; | ||
} |
12 changes: 12 additions & 0 deletions
12
...ation.Tests/Resources/UnbindAllBindables/Static/Generated/g_Static_UnbindAllBindables.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// <auto-generated/> | ||
#nullable enable | ||
#pragma warning disable CS4014 | ||
|
||
partial class Static : global::osu.Framework.Graphics.ISourceGeneratedUnbindAllBindables | ||
{ | ||
global::System.Type global::osu.Framework.Graphics.ISourceGeneratedUnbindAllBindables.KnownType => typeof(global::Static); | ||
public override void InternalUnbindAllBindables() | ||
{ | ||
base.InternalUnbindAllBindables(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
osu.Framework.SourceGeneration.Tests/Resources/UnbindAllBindables/Static/Sources/Static.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public partial class Static : osu.Framework.Graphics.Drawable | ||
{ | ||
public static readonly osu.Framework.Bindables.Bindable<int> Bindable1 = new osu.Framework.Bindables.Bindable<int>(); | ||
} |
32 changes: 32 additions & 0 deletions
32
...ework.SourceGeneration.Tests/UnbindAllBindables/UnbindAllBindablesSourceGeneratorTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Threading.Tasks; | ||
using Xunit; | ||
using VerifyCS = osu.Framework.SourceGeneration.Tests.Verifiers.CSharpSourceGeneratorVerifier<osu.Framework.SourceGeneration.Generators.UnbindAllBindables.UnbindAllBindablesSourceGenerator>; | ||
|
||
namespace osu.Framework.SourceGeneration.Tests.UnbindAllBindables | ||
{ | ||
public class UnbindAllBindablesSourceGeneratorTests : AbstractGeneratorTests | ||
{ | ||
protected override string ResourceNamespace => "UnbindAllBindables"; | ||
|
||
[Theory] | ||
[InlineData("Basic")] | ||
[InlineData("AutoProperty")] | ||
[InlineData("ExplicitImplementation")] | ||
[InlineData("Static")] | ||
[InlineData("Nullable")] | ||
public Task Check(string name) | ||
{ | ||
GetTestSources(name, | ||
out (string filename, string content)[] commonSourceFiles, | ||
out (string filename, string content)[] sourceFiles, | ||
out (string filename, string content)[] commonGeneratedFiles, | ||
out (string filename, string content)[] generatedFiles | ||
); | ||
|
||
return VerifyCS.VerifyAsync(commonSourceFiles, sourceFiles, commonGeneratedFiles, generatedFiles); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
osu.Framework.SourceGeneration/Generators/UnbindAllBindables/BindableDefinition.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
namespace osu.Framework.SourceGeneration.Generators.UnbindAllBindables | ||
{ | ||
public readonly struct BindableDefinition | ||
{ | ||
public readonly string Name; | ||
public readonly string FullyQualifiedContainingType; | ||
public readonly bool IsNullable; | ||
|
||
public BindableDefinition(string name, string fullyQualifiedContainingType, bool isNullable) | ||
{ | ||
Name = name; | ||
FullyQualifiedContainingType = fullyQualifiedContainingType; | ||
IsNullable = isNullable; | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...mework.SourceGeneration/Generators/UnbindAllBindables/UnbindAllBindablesSemanticTarget.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
||
namespace osu.Framework.SourceGeneration.Generators.UnbindAllBindables | ||
{ | ||
public class UnbindAllBindablesSemanticTarget : IncrementalSemanticTarget | ||
{ | ||
public readonly List<BindableDefinition> Bindables = new List<BindableDefinition>(); | ||
|
||
public UnbindAllBindablesSemanticTarget(ClassDeclarationSyntax classSyntax, SemanticModel semanticModel) | ||
: base(classSyntax, semanticModel) | ||
{ | ||
} | ||
|
||
protected override bool CheckValid(INamedTypeSymbol symbol) => isDrawableSubType(symbol); | ||
|
||
protected override bool CheckNeedsOverride(INamedTypeSymbol symbol) => !isDrawableType(symbol); | ||
|
||
protected override void Process(INamedTypeSymbol symbol) | ||
{ | ||
foreach (IFieldSymbol bindableField in enumerateBindables(symbol)) | ||
{ | ||
bool isNullable = bindableField.NullableAnnotation == NullableAnnotation.Annotated; | ||
|
||
if (bindableField.IsImplicitlyDeclared) | ||
{ | ||
// Compiler generated names are of the form "<Name>k__BackingField". | ||
string name = bindableField.Name.Substring(1, bindableField.Name.IndexOf('>') - 1); | ||
string containingType = GlobalPrefixedTypeName; | ||
|
||
// In the case of explicit auto-property implementations, the name will contain the containing type (interface name). | ||
int containingTypeIndex = name.LastIndexOf('.'); | ||
|
||
if (containingTypeIndex != -1) | ||
{ | ||
containingType = name.Substring(0, containingTypeIndex); | ||
name = name.Substring(containingTypeIndex + 1); | ||
} | ||
|
||
Bindables.Add(new BindableDefinition(name, containingType, isNullable)); | ||
} | ||
else | ||
Bindables.Add(new BindableDefinition(bindableField.Name, GlobalPrefixedTypeName, isNullable)); | ||
} | ||
} | ||
|
||
private IEnumerable<IFieldSymbol> enumerateBindables(INamedTypeSymbol symbol) | ||
{ | ||
return symbol.GetMembers() | ||
.OfType<IFieldSymbol>() | ||
.Where(m => !m.IsStatic) | ||
.Where(m => m.Type.AllInterfaces.Any(SyntaxHelpers.IsIUnbindableInterface)); | ||
} | ||
|
||
private bool isDrawableSubType(INamedTypeSymbol type) | ||
{ | ||
INamedTypeSymbol? s = type; | ||
|
||
while (s != null) | ||
{ | ||
if (isDrawableType(s)) | ||
return true; | ||
|
||
s = s.BaseType; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private bool isDrawableType(INamedTypeSymbol type) | ||
=> type.Name == "Drawable" && SyntaxHelpers.GetFullyQualifiedTypeName(type) == "osu.Framework.Graphics.Drawable"; | ||
Comment on lines
+75
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Repeat of #5761 (comment). Should probably be moved out to |
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So this means that the generator is going to emit code for every drawable subtype, even if it doesn't introduce any new bindables to unbind? Do we care, and if we do, how much of a pain is it to have it only emit when necessary?