Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

[RFC] Allocation optimization for translation cases #6545

Closed
Therzok opened this issue Nov 3, 2018 · 0 comments
Closed

[RFC] Allocation optimization for translation cases #6545

Therzok opened this issue Nov 3, 2018 · 0 comments

Comments

@Therzok
Copy link
Contributor

Therzok commented Nov 3, 2018

Currently, GettextCatalog.GetString has the following behaviour:

  1. Take the parameter string and marshal it to native
  2. Take the translated return value and marshal it to managed

When assigning a string to a widget property, the following happens:

  1. The managed string is marshalled to native handle
  2. The string is then strdup'd in native

The usual pattern is:

  1. call GettextCatalog.GetString("value")
  2. a. Assign the string to widget property
  3. b. Format the string and then assign it to widget property.

That means we have a total of:

  • 3 native allocations and 1 managed allocations for the simple translatable string
  • 3 native allocations and 2+N managed allocations for the formattable translatable string (where N is the number of format arguments)

The 3 native allocations are: marshal to native for gettext, marshal to native for setting the widget property and 1 native allocation for strdup'ing the string.

The managed allocations are: native to managed for gettext, and in the latter case, string.format

Problem:
❗️ We allocate too many strings and marshal them unnecessarily.

Pre-requisites:
❗️ Gtk# and/or Xamarin.Mac need to support setting a string handle directly, rather than doing the marshalling for us.

Whilst we cannot do anything for the formatting case, as we need a managed string to format, the simple assignment case can be reduced to just:

widget.LabelHandle = GettextCatalog.GetStringHandle ("value")

The result:
1 managed to native allocation -> gettext
1 native allocation -> strdup when handle is set in native

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant