Skip to content

Conversation

@AyushDharDubey
Copy link
Contributor

Closes #3909

This PR rewires the Locales constructor to accept an existing Configuration instance via a config= parameter, instead of instantiating a new (empty) configuration on each call.

The constructor remains forgiving by allowing config=None for call sites where a configuration object is not available in context for example.

By reusing a single Configuration instance where possible, this avoids repeated configuration loading and significantly reduces per-request overhead by over 25-30% per request.

@AyushDharDubey AyushDharDubey changed the title Fix/issue 3909 Reuse Configuration instance in Locales Dec 16, 2025
@AyushDharDubey AyushDharDubey marked this pull request as draft December 16, 2025 17:16
@AyushDharDubey AyushDharDubey marked this pull request as ready for review December 16, 2025 18:18
Copy link
Member

@lonvia lonvia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor remains forgiving by allowing config=None for call sites where a configuration object is not available in context for example.

Looking at the line you cite here:

locales = options.get('locales', Locales())

I notice it was badly written. Locale() will always be instantiated here, even when it is available in the options dict. This should be: locales = options.get('locales') or Locales().

And I don't think the code path where Locales() is instantiated is actually reachable afterwards.

Copy link
Member

@lonvia lonvia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind squashing together your commits into a single one. Then this would be ready to merge.

expect output names as argument and avoid redundant configuration initialization
@lonvia lonvia merged commit 26e62fd into osm-search:master Dec 22, 2025
8 checks passed
@lonvia
Copy link
Member

lonvia commented Dec 22, 2025

Thank you!

@AyushDharDubey AyushDharDubey deleted the fix/issue_3909 branch December 22, 2025 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API Performance issues and dotenv_values()

2 participants