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

Test-XliffTranslations: don't append items to existing arrays #18

Closed
jhoek opened this issue Nov 23, 2021 · 4 comments · Fixed by #27
Closed

Test-XliffTranslations: don't append items to existing arrays #18

jhoek opened this issue Nov 23, 2021 · 4 comments · Fixed by #27
Labels
enhancement New feature or request shipped Issue is available in the public release.

Comments

@jhoek
Copy link
Contributor

jhoek commented Nov 23, 2021

In Test-XliffTranslations, you append (potentially numerous) items to the $missingTranslationUnits and $needWorkTranslationUnits arrays. In PowerShell (.NET), this is an expensive operation (increasingly so for larger arrays) that can easily be avoided by capturing the items emitted (i.c. by the ForEach-Object command), then storing them in an array all at once.

Please consider the performance difference in the (admittedly simple) example below.

CleanShot 2021-11-23 at 14 18 03@2x

@jhoek
Copy link
Contributor Author

jhoek commented Nov 23, 2021

The same appears to apply to the return value of Test-XliffTranslations:

return $missingTranslationUnits + $needWorkTranslationUnits;

Instead of combining the two existing arrays into a newly allocated array that you subsequently return, please consider returning the arrays separately, one after the other. To illustrate the difference, here's another simplified example:

CleanShot 2021-11-23 at 15 01 48@2x

@rvanbekkum
Copy link
Owner

Thanks for your suggestion. I will look into it when I have the time. If you have ideas of which changes to make, then feel free to make a PR as well. :)

@rvanbekkum rvanbekkum added the enhancement New feature or request label Nov 23, 2021
@jhoek
Copy link
Contributor Author

jhoek commented Nov 30, 2021

In order to use the logic from my first example above, you'd probably have to loop through the translation units twice - once to capture missing entries, and once for capturing entries with problems. Looping twice, of course, comes at a certain performance cost as well, so in this case, we may be better off collecting entries in a collection of a type that does not require reallocation when adding items. My personal preference, for type safety reasons, would be to use a generic List.

When a List is written to the output stream, it is automatically unraveled, as you can read here: https://stackoverflow.com/questions/38257354/preserving-powershell-function-return-type. This means that the output type (i.c. the XML node that represents the translation unit) will remain the same as before.

@rvanbekkum rvanbekkum reopened this Dec 3, 2021
@rvanbekkum rvanbekkum added ships-in-future-update Resolution will be available in the next release. shipped Issue is available in the public release. and removed ships-in-future-update Resolution will be available in the next release. labels Dec 3, 2021
@rvanbekkum
Copy link
Owner

Shipped in version 1.5.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request shipped Issue is available in the public release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants