refactor(field_formatter): use Spark transformer for field-name cache#71
Merged
Torkan merged 1 commit intoash-project:mainfrom Apr 30, 2026
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 oneSpark.Dsl.Extension.get_persisted/2call. Preserves thetypescript_field_names/0callback precedence over the DSL.Changes
AshTypescript.Resource.Transformers.PersistFormattedFields— walks public attributes, relationships, calculations, and aggregates; persists(field, builtin_formatter) -> formatted_stringat compile time.field_namesDSL overrides are baked into the same map.AshTypescript.Resource.Info.get_formatted_field/3— exposes the persisted lookup.format_field_for_client/3reads the persisted state on the hot path. Resources withtypescript_field_names/0, non-builtin (MFA) formatters, and non-AshTypescript.Resourcemodules fall through to the existing runtime path unchanged.Performance
Comparable to PR #68 with different tradeoffs across request shapes:
mix run benchmarks/output_formatter.exs: 5.14 ms vs 4.65 ms.Preserves the bulk of PR #68's improvement vs pre-#68 baseline. For a 1500-record response (
mix run benchmarks/output_formatter.exs):Contributor checklist
Leave anything that you believe does not apply unchecked.