yonaskolb / yonaskolb/XcodeGen

[ENHANCEMENT] Improve performance in `SpecValidation.validateSettings` function

Open
#1,521 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
8.8k
Forks
908
Avg merge
17d 14h
Merged PRs (30d)
2

Description

Descrição:

Hello there, it's my first time here!

I was reading how XcodeGen works and I noticed an improvement using early break in loops on SpecValidation.validateSettings that can be done.

Snipped of code that I would change
image

My points to consider here:

  1. Reduce nested if, the condition on line 23 errors.append(.invalidBuildSettingConfig(config)) happens when line 21 and 22 it's true, so don't need to have 2 ifs, instead can be only 1 with 2 validations.
  2. Early break in loops
    2.1. On loop in line 32, once the validation at line 33 it's true, in line 34 sets isConfig = true and isConfig will never be false in the rest of iteration of line 32, so it's no longer necessary iterate over the rest
    2.2. Using the same idea on 2.1, on the outer loop at line 30, once the validation at line 37 it's true, in line 38 sets allConfigs = false and allConfigs will never be true again. So the outer loop can be stopped.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the Swift SpecValidation.validateSettings function and compare its nested conditions and outer and inner loops with the proposed early exits. Preserve the existing validation errors while stopping each loop once its result cannot change; done means the validation behavior remains correct and the unnecessary iterations are removed.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.