[GH-ISSUE #95] Conversion to Base64 is slow, slowing embedding images and loading Graph config file #36

Closed
opened 2026-02-27 20:30:55 +03:00 by kerem · 1 comment
Owner

Originally created by @GruberMarkus on GitHub (Nov 22, 2023).
Original GitHub issue: https://github.com/Set-OutlookSignatures/Set-OutlookSignatures/issues/95

Originally assigned to: @GruberMarkus on GitHub.

With v4.8.0, Set-OutlookSignatures introduces the option to configure a custom HTML site to be displayed after the successful or unsuccessful authentication to Graph.

The "default graph config.ps1" file contains samples for this HTML code, and shows how to embed images.

Since this feature has been introduced, the load time of the default graph config file is much higher - on several of my systems, it takes 14 seconds longer than in older releases.

The reason for this is the way how images are converted to Base64 strings for embedding.

The actual conversion happens through calling [System.Convert]::ToBase64String(), and this is very fast.

What is slow is reading the image files content and converting it to a byte array.
Currently, Get-Content '.\path\to\file.png' is used with the -Encoding Byte (PowerShell Desktop) or -AsByteStream (PowerShell Core) parameter. This turns out to be very slow, because PowerShell converts every single byte to the [object] type first.

This can be solved by not relying on PowerShell cmdlets to get the file content as byte array, but using the .Net method [System.IO.File]::ReadAllBytes() instead.

Reading all bytes of the Set-OutlookSignatures logo with Get-Content roughly takes 7 seconds, while ReadAllBytes() gives the same in less than 0.2 seconds.

The way around this performance issue is to switch from Get-Content to ReadAllBytes().

Originally created by @GruberMarkus on GitHub (Nov 22, 2023). Original GitHub issue: https://github.com/Set-OutlookSignatures/Set-OutlookSignatures/issues/95 Originally assigned to: @GruberMarkus on GitHub. With v4.8.0, Set-OutlookSignatures introduces the option to configure a custom HTML site to be displayed after the successful or unsuccessful authentication to Graph. The "default graph config.ps1" file contains samples for this HTML code, and shows how to embed images. Since this feature has been introduced, the load time of the default graph config file is much higher - on several of my systems, it takes 14 seconds longer than in older releases. The reason for this is the way how images are converted to Base64 strings for embedding. The actual conversion happens through calling `[System.Convert]::ToBase64String()`, and this is very fast. What is slow is reading the image files content and converting it to a byte array. Currently, `Get-Content '.\path\to\file.png'` is used with the `-Encoding Byte` (PowerShell Desktop) or `-AsByteStream` (PowerShell Core) parameter. This turns out to be very slow, because PowerShell converts every single byte to the [object] type first. This can be solved by not relying on PowerShell cmdlets to get the file content as byte array, but using the .Net method `[System.IO.File]::ReadAllBytes()` instead. Reading all bytes of the Set-OutlookSignatures logo with `Get-Content` roughly takes 7 seconds, while `ReadAllBytes()` gives the same in less than 0.2 seconds. The way around this performance issue is to switch from `Get-Content` to `ReadAllBytes()`.
kerem closed this issue 2026-02-27 20:30:55 +03:00
Author
Owner

@GruberMarkus commented on GitHub (Nov 22, 2023):

The issue and the benchmark data are confirmed.

The proposed solution will be included in the next release. It will not only reduce load times for the Graph config file, but also speed up the process of embedding images in signatures.

<!-- gh-comment-id:1822564305 --> @GruberMarkus commented on GitHub (Nov 22, 2023): The issue and the benchmark data are confirmed. The proposed solution will be included in the next release. It will not only reduce load times for the Graph config file, but also speed up the process of embedding images in signatures.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Set-OutlookSignatures-Set-OutlookSignatures#36
No description provided.