Make Java measure thread-safe. #60

Merged
tcmulcahy merged 1 commits from thread-safe-measure into master 2015-03-27 10:01:33 -07:00
tcmulcahy commented 2015-03-23 10:58:21 -07:00 (Migrated from github.com)

The measure method in java previously referenced a global MEASURE_OUTPUT variable. This means that css layout could not be done safely from multiple threads. The naive solution would be to create a MeasureOutput on each measure invocation, but since Android is sensitive to allocation and garbage collection, we instead force a MeasureOutput instance to be passed in to calculateLayout. Since it would be strange and non-intuitive to pass MeasureOutput to calculateLayout, this implementation detail is hidden from clients by wrapping the MeasureOutput in a CSSLayoutContext object. Clients are free to re-use the same CSSLayoutContext object, provided that they ensure it is not used concurrently from multiple threads.

The measure method in java previously referenced a global MEASURE_OUTPUT variable. This means that css layout could not be done safely from multiple threads. The naive solution would be to create a MeasureOutput on each measure invocation, but since Android is sensitive to allocation and garbage collection, we instead force a MeasureOutput instance to be passed in to calculateLayout. Since it would be strange and non-intuitive to pass MeasureOutput to calculateLayout, this implementation detail is hidden from clients by wrapping the MeasureOutput in a CSSLayoutContext object. Clients are free to re-use the same CSSLayoutContext object, provided that they ensure it is not used concurrently from multiple threads.
vjeux commented 2015-03-23 11:05:42 -07:00 (Migrated from github.com)

@kmagiera or @astreet can you review this?

@kmagiera or @astreet can you review this?
kmagiera commented 2015-03-25 17:58:24 -07:00 (Migrated from github.com)

Thanks! Looks good, please just add a class level comment to CSSLayoutContext that will explain the purpose of this class and that a separate instance should be used when calculateLayout is called concurrently for different node hierarchies.

Thanks! Looks good, please just add a class level comment to CSSLayoutContext that will explain the purpose of this class and that a separate instance should be used when calculateLayout is called concurrently for different node hierarchies.
tcmulcahy commented 2015-03-26 15:32:40 -07:00 (Migrated from github.com)

Okay, I've added the javadoc, and also fixed a long line.

Okay, I've added the javadoc, and also fixed a long line.
Sign in to join this conversation.
No description provided.