Skip to content

Refactor flexbox layout algorithm into multiple functions #43

@TimJentzsch

Description

@TimJentzsch

What problem does this solve or what need does it fill?

The current implementation is very tightly coupled and will be hard to maintain in the future. The compute_internal function has about 1k lines of code-- this will not be sustainable in the long run and might lead to code duplication once we have multiple layout algorithms.

What solution would you like?

The compute_internal function should be split up into multiple smaller functions that correspond to the steps of the layout algorithm. Each function should clearly document the spec that it implements, ideally also linking to the spec docs. The original function can then simply call the steps one-by-one, similar to the template method pattern.

We need to carefully watch how this affects performance using benchmarks, probably adding #[inline] annotations to each step.

In the future we should also have tests for each step to make sure that we fully correspond to the spec. This can be done in a separate PR though.

Acceptance Criteria

  • compute_internal has been separated into multiple functions, corresponding to the steps of the layout algorithm.
  • #[allow(clippy::cognitive_complexity)] has been removed.
  • Each function is documented, referencing the flexbox specs.
  • No functional changes have been made.
  • The benchmarks don't show any major performance regressions.

Additional context

This will be the first step towards improving the functionality of the layout algorithm with #39.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions