Skip to content

Fix config.Root calculation #199

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

Merged
merged 7 commits into from
Jan 24, 2020

Conversation

IgorFedchenko
Copy link
Contributor

@IgorFedchenko IgorFedchenko commented Jan 24, 2020

Close #195

@Aaronontheweb This is based on #197 , so may be better to review/merge that one first.

The main improvement here is not only the fact that Root is not calculated on config creation - also Config instance now is not modified due to any private methods after is created with constructor.

Before there were some private setters, that were making harder to with Config as with immutable data structure. Now it is refactored to be fully built on constructor invocation, and we are safe to write code in this class without breaking immutability (of cause if we will not touch property setters).

@IgorFedchenko
Copy link
Contributor Author

Ideally we should have all HOCON inner structures immutable, because all of this bugs are coming because entities reference each other and can modify each other, making it quite messy to debug.

That nice moment, when the value is changed because of you just viewed it in your debugger...

But this is much more major task then fixing Config class.

@IgorFedchenko
Copy link
Contributor Author

Since #198 turned out to be a mistake, rolled back it's changes. Now should be just fine.


// If Fallback is not set - we will set it in new copy
// If Fallback was set - just use it, but with adding new fallback values
return new Config((HoconValue) Value.Clone(null), Fallback?.WithFallback(fallback) ?? fallback);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turned out to be much more elegant solution for getting new config with fallback, and without internal state mutations.

return aggregated;
}
}
public virtual HoconValue Root { get; }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this is where we will safe on allocations. Root is immutable and calculated only once, in constructor

Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -54,27 +66,12 @@ public Config(HoconRoot root) : base(root?.Value, root?.Substitutions ?? Enumera
/// <summary>
/// The configuration used as a secondary source.
/// </summary>
public Config Fallback { get; private set; }
public Config Fallback { get; }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fallback should never change. It is either set, or not set for given config.

Copy link
Member

Choose a reason for hiding this comment

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

Great idea.

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

Amazing improvements here. Nice work.

@@ -54,27 +66,12 @@ public Config(HoconRoot root) : base(root?.Value, root?.Substitutions ?? Enumera
/// <summary>
/// The configuration used as a secondary source.
/// </summary>
public Config Fallback { get; private set; }
public Config Fallback { get; }
Copy link
Member

Choose a reason for hiding this comment

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

Great idea.

return aggregated;
}
}
public virtual HoconValue Root { get; }
Copy link
Member

Choose a reason for hiding this comment

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

👍

/// <summary>
/// Performs aggregation of Value and all Fallbacks into single <see cref="HoconValue"/> object
/// </summary>
private HoconValue GetRootValue()
Copy link
Member

Choose a reason for hiding this comment

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

I'm much happier with this now that it's only run once.

@Aaronontheweb Aaronontheweb merged commit cabbdde into akkadotnet:dev Jan 24, 2020
@IgorFedchenko IgorFedchenko deleted the fix/root-calculation branch January 24, 2020 16:04
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.

Lookups on configs with fallback are performing merge and allocations each time
2 participants