Skip to content

refactor(field_formatter): use Spark transformer for field-name cache#71

Merged
Torkan merged 1 commit intoash-project:mainfrom
mike1o1:module-transform-formatting-change
Apr 30, 2026
Merged

refactor(field_formatter): use Spark transformer for field-name cache#71
Torkan merged 1 commit intoash-project:mainfrom
mike1o1:module-transform-formatting-change

Conversation

@mike1o1
Copy link
Copy Markdown
Contributor

@mike1o1 mike1o1 commented Apr 30, 2026

Summary

Replaces the per-process-dictionary cache from #68 with a compile-time Spark transformer that persists every (field, formatter) pair via Spark.Dsl.Transformer.persist/3. Runtime lookup is one Spark.Dsl.Extension.get_persisted/2 call. Preserves the typescript_field_names/0 callback precedence over the DSL.

Changes

  • New AshTypescript.Resource.Transformers.PersistFormattedFields — walks public attributes, relationships, calculations, and aggregates; persists (field, builtin_formatter) -> formatted_string at compile time. field_names DSL overrides are baked into the same map.
  • New AshTypescript.Resource.Info.get_formatted_field/3 — exposes the persisted lookup.
  • format_field_for_client/3 reads the persisted state on the hot path. Resources with typescript_field_names/0, non-builtin (MFA) formatters, and non-AshTypescript.Resource modules fall through to the existing runtime path unchanged.

Performance

Comparable to PR #68 with different tradeoffs across request shapes:

Preserves the bulk of PR #68's improvement vs pre-#68 baseline. For a 1500-record response (mix run benchmarks/output_formatter.exs):

State Time Memory
Pre-#68 (no optimization) 71.87 ms 61.61 MB
PR #68 (process-dict cache) 4.65 ms 5.72 MB
This PR (Spark transformer) 5.14 ms 5.96 MB

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

Replaces the per-process-dictionary cache from ash-project#68 with a compile time Spark transformer that persists every (field, formatter) pair via `Spark.Dsl.Transformer.persist/3`. Runtime lookup is one `Spark.Dsl.Extension.get_persisted/2` call. Preserves the `typescript_field_names/0` callback precedence over the DSL.
@Torkan Torkan merged commit 18b6584 into ash-project:main Apr 30, 2026
25 checks passed
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.

2 participants