Resource limits

Copy Markdown

FeedReader parses XML incrementally, but it retains feed metadata, the current item, pending stream events, and—when collecting—a list of items. Configure limits for the resources that matter to your workload. Invalid values generally fall back to their defaults; the options below accept non-negative integers unless noted.

XML parsing limits

OptionDefaultBounds
:max_detection_bytes65,536 bytesPrefix inspected to detect a format; must be positive.
:chunk_size65,536 bytesXML input chunks and SAX character-data callback sizing; must be positive.
:max_xml_events1,000,000SAX events processed.
:max_xml_depth256Nested XML element depth.
:max_attributes_per_element128Attributes on one element.
:max_attribute_bytes65,536 bytesCombined name and value size of an individual attribute.
:max_feed_metadata_bytes1 MiBRetained feed metadata.
:max_item_bytes4 MiBRetained content for the current item.
:max_queue_bytesDefaults to :max_item_bytesSerialized size of one pending event.

Zero is a valid limit for the non-negative resource budgets. A zero-byte metadata or item budget, for example, rejects retained data in that scope. Invalid XML-limit values use defaults. An invalid :max_detection_bytes disables detection; supply a valid explicit :format to parse in that case.

Example for stricter parsing budgets:

FeedReader.stream_file("priv/feed.xml",
  max_xml_events: 100_000,
  max_xml_depth: 64,
  max_attributes_per_element: 32,
  max_feed_metadata_bytes: 256_000,
  max_item_bytes: 1_000_000,
  max_queue_bytes: 1_000_000
)

Limit failures use the form {:error, {:resource_limit, option, limit}} from collection APIs. In a stream, parsing errors are delivered as a terminal {:error, reason} event.

Remote download limits

Remote APIs accept these additional budgets:

OptionDefaultBounds
:max_compressed_bytes50 MiBRaw response bytes received.
:max_decoded_bytes50 MiBBytes after gzip/deflate decoding.
:max_temp_bytes50 MiBDecoded bytes staged in the temporary file.
:max_expansion_ratio100Decoded-to-compressed byte ratio.

The limits are checked while chunks are consumed. A failure removes any temporary file created for the download. Content encodings supported by the default pipeline are identity, gzip, and deflate; unsupported or stacked encodings are rejected.

Collection limits

parse_file/2, parse_binary/2, parse_stream/2, and fetch_and_parse/2 require a positive :max_items. The optional one-argument :item_filter rejects items before they are counted and retained.

The item limit bounds retained item count, not input bytes, total parser work, or network transfer. For remote feeds, the full response is downloaded before parsing. Collection continues consuming parser events and returns no partial result if an accepted item exceeds the item limit. Combine :max_items with download and XML limits when you need those separate guarantees.

Verified APIs additionally accept :max_parse_passes, defaulting to 5, to bound validation and event-delivery passes. An invalid value uses the default.