Skip to content

feat: accept the data dictionary as a value in SessionConfig - #355

Open
fraVlaca wants to merge 1 commit into
Validus-Risk-Management:mainfrom
fraVlaca:feat/dictionary-value
Open

fraVlaca wants to merge 1 commit into
Validus-Risk-Management:mainfrom
fraVlaca:feat/dictionary-value

Conversation

@fraVlaca

Copy link
Copy Markdown

Problem

A custom data dictionary can only be supplied as a file path (data_dictionary_path). Two situations make that awkward:

  • A counterparty dialect is often a standard dictionary plus a handful of custom fields. Building or extending it in memory is simpler and safer than writing an XML file to disk and pointing the config at it.
  • A process that runs many sessions (for example one per account or per venue) builds a separate MessageBuilder for every session, each holding its own copy of the dictionary. A FIX 4.4 dictionary is close to 1 MB, so memory grows linearly with the number of sessions even when they all use the same dictionary.

Change

  • SessionConfig::data_dictionary: Option<Arc<Dictionary>>, #[serde(skip)] so it is set in code only. When set, it takes precedence over data_dictionary_path and the built-in dictionary for the BeginString.
  • Sessions given the same Arc<Dictionary> and the same validate_user_defined_fields setting share one MessageBuilder. The shared builders are held weakly in a small process-wide registry, so a builder is dropped with the last session using it and dead entries are pruned on the next lookup. Sessions configured without a dictionary value are unchanged and keep a builder each.
  • SessionCtx::message_builder becomes Arc<MessageBuilder>.
  • Every SessionConfig struct literal in the workspace (unit tests, integration tests and the load-testing example) gains data_dictionary: None. This is a new public field, so downstream code that builds SessionConfig with a struct literal needs the same one-line addition.

Tests

  • test_sessions_with_the_same_dictionary_value_share_a_message_builder: the same Arc and validation setting return the same builder; a different validation setting, or an equal dictionary in a different Arc, get their own.
  • test_shared_message_builder_is_dropped_with_its_last_session: the registry does not keep a builder alive once its last holder is dropped.

I could not build this workspace locally, so I am relying on CI for the compile, clippy and test run.

This contribution is offered under the project's MIT licence.

Add SessionConfig::data_dictionary: Option<Arc<Dictionary>>, which takes
precedence over data_dictionary_path. A dictionary can then be built or
extended in memory (a standard dictionary plus a counterparty's custom
fields) instead of being read from a file.

Sessions given the same Arc and the same validation settings share one
MessageBuilder, held weakly in a process-wide registry, so a process
running many sessions with one dictionary pays for its parser once.
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.

1 participant