Skip to content
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

new trimmer feature System.TimeZoneInfo.Invariant #111215

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion docs/design/features/timezone-invariant-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,28 @@ Therefore dotnet bundles the timezone database as binary as part of the runtime.
That makes download size larger and application startup slower.
If your application doesn't need to work with time zone information, you could use this feature to make the runtime about 200KB smaller.

You enable it in project file:
## Enabling the invariant mode

Applications can enable the invariant mode by either of the following:

1. in project file:

```xml
<PropertyGroup>
<InvariantTimezone>true</InvariantTimezone>
</PropertyGroup>
```

2. in `runtimeconfig.json` file:

```json
{
"runtimeOptions": {
"configProperties": {
"System.TimeZoneInfo.Invariant": true
}
}
}
```

3. setting environment variable value `DOTNET_SYSTEM_TIMEZONE_INVARIANT` to `true` or `1`.
pavelsavara marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public TrimmingArgumentBuilder (TestCaseMetadataProvider metadataProvider)
Options.FeatureSwitches.Add ("System.Text.Encoding.EnableUnsafeUTF7Encoding", false);
Options.FeatureSwitches.Add ("System.Diagnostics.Tracing.EventSource.IsSupported", false);
Options.FeatureSwitches.Add ("System.Globalization.Invariant", true);
Options.FeatureSwitches.Add ("System.TimeZoneInfo.Invariant", true);
pavelsavara marked this conversation as resolved.
Show resolved Hide resolved
Options.FeatureSwitches.Add ("System.Resources.UseSystemResourceKeys", true);

Options.FrameworkCompilation = false;
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/tools/aot/ILCompiler/repro/repro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<ReproResponseLines Include="--feature:System.Linq.Expressions.CanEmitObjectArrayDelegate=false" />
<ReproResponseLines Include="--feature:System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported=false" />
<ReproResponseLines Include="--feature:System.Globalization.Invariant=true" />
<ReproResponseLines Include="--feature:System.TimeZoneInfo.Invariant=true" />
pavelsavara marked this conversation as resolved.
Show resolved Hide resolved
<ReproResponseLines Include="--feature:System.Diagnostics.Debugger.IsSupported=false" />
<ReproResponseLines Include="--feature:System.StartupHookProvider.IsSupported=false" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@
<PlatformManifestFileEntry Include="wasi-link.rsp" IsNative="true" />
<PlatformManifestFileEntry Include="ILLink.Substitutions.WasmIntrinsics.xml" IsNative="true" />
<PlatformManifestFileEntry Include="ILLink.Substitutions.NoWasmIntrinsics.xml" IsNative="true" />
<PlatformManifestFileEntry Include="ILLink.Substitutions.LegacyJsInterop.xml" IsNative="true" />
<!-- wasi specific -->
<PlatformManifestFileEntry Include="main.c" IsNative="true" />
<PlatformManifestFileEntry Include="driver.h" IsNative="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<type fullname="System.Globalization.GlobalizationMode/Settings">
<method signature="System.Boolean get_Invariant()" body="stub" value="false" feature="System.Globalization.Invariant" featurevalue="false" />
</type>
<type fullname="System.TimeZoneInfo">
<method signature="System.Boolean get_Invariant()" body="stub" value="true" feature="System.TimeZoneInfo.Invariant" featurevalue="true" />
</type>
<type fullname="System.Resources.ResourceReader">
<method signature="System.Boolean InitializeBinaryFormatter()" body="stub" value="false" feature="System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization" featurevalue="false" />
</type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ private static TimeZoneInfoResult TryGetTimeZoneFromLocalMachineCore(string id,
/// </remarks>
private static IEnumerable<string> GetTimeZoneIds()
{
if (Invariant)
{
return Array.Empty<string>();
}

try
{
var fileName = Path.Combine(GetTimeZoneDirectory(), TimeZoneFileName);
Expand Down Expand Up @@ -469,6 +474,11 @@ private static bool TryLoadTzFile(string tzFilePath, [NotNullWhen(true)] ref byt
#if TARGET_WASI || TARGET_BROWSER
private static bool TryLoadEmbeddedTzFile(string name, [NotNullWhen(true)] out byte[]? rawData)
{
if (Invariant)
{
rawData = null;
return false;
}
IntPtr bytes = Interop.Sys.GetTimeZoneData(name, out int length);
if (bytes == IntPtr.Zero)
{
Expand Down Expand Up @@ -504,6 +514,10 @@ private static bool TryGetLocalTzFile([NotNullWhen(true)] out byte[]? rawData, [
{
rawData = null;
id = null;
if (Invariant)
{
return false;
}
string? tzVariable = GetTzEnvironmentVariable();

// If the env var is null, on iOS/tvOS, grab the default tz from the device.
Expand Down Expand Up @@ -573,6 +587,11 @@ private static bool TryGetLocalTzFile([NotNullWhen(true)] out byte[]? rawData, [
/// </summary>
private static TimeZoneInfo GetLocalTimeZoneFromTzFile()
{
if (Invariant)
{
return Utc;
}

byte[]? rawData;
string? id;
if (TryGetLocalTzFile(out rawData, out id))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ private enum TimeZoneInfoResult
private static readonly TimeZoneInfo s_utcTimeZone = CreateUtcTimeZone();
private static CachedData s_cachedData = new CachedData();

internal static bool Invariant { get; } = AppContextConfigHelper.GetBooleanConfig("System.TimeZoneInfo.Invariant", "DOTNET_SYSTEM_TIMEZONE_INVARIANT");
pavelsavara marked this conversation as resolved.
Show resolved Hide resolved

//
// All cached data are encapsulated in a helper class to allow consistent view even when the data are refreshed using ClearCachedData()
//
Expand Down
4 changes: 3 additions & 1 deletion src/mono/browser/runtime/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ mono_wasm_load_runtime (int debug_level)
monovm_initialize (2, appctx_keys, appctx_values);

#ifndef INVARIANT_TIMEZONE
mono_register_timezones_bundle ();
char* invariant_timezone = monoeg_g_getenv ("DOTNET_SYSTEM_TIMEZONE_INVARIANT");
if (strcmp(invariant_timezone, "true") != 0 && strcmp(invariant_timezone, "1") != 0)
mono_register_timezones_bundle ();
#endif /* INVARIANT_TIMEZONE */

root_domain = mono_wasm_load_runtime_common (debug_level, wasm_trace_logger, interp_opts);
Expand Down
4 changes: 3 additions & 1 deletion src/mono/wasi/runtime/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ mono_wasm_load_runtime (int debug_level)
monovm_initialize (2, appctx_keys, appctx_values);

#ifndef INVARIANT_TIMEZONE
mono_register_timezones_bundle ();
char* invariant_timezone = monoeg_g_getenv ("DOTNET_SYSTEM_TIMEZONE_INVARIANT");
if (strcmp(invariant_timezone, "true") != 0 && strcmp(invariant_timezone, "1") != 0)
mono_register_timezones_bundle ();
#endif /* INVARIANT_TIMEZONE */
#ifdef WASM_SINGLE_FILE
mono_register_assemblies_bundle ();
Expand Down
Loading