Skip to content

Conversation

@jcoglan
Copy link
Contributor

@jcoglan jcoglan commented Jan 29, 2026

Overview

While working on mango_selector:match() to implement detailed match failure information, I noticed that every time a non-operator field is evaluated, we call mango_doc:get_field(), which calls mango_util:parse_field() if its input is a binary. We can avoid re-parsing fields so often by changing norm_fields so that it normalizes to the parsed form [<<"a">>, <<"b">>] instead of <<"a.b">>.

The changes have made the benchmarks I added about 30-40% faster. (I wasn't sure where benchmarks like this should live, if anywhere... they're mostly here for me to check the effect and I'm happy to move or remove them before merging.)

In the first commit here I make this change and then change all the other logic that interacts with selectors to also use this form. This ended up having a bigger blast radius than I would have liked, so I undid most of it and changed the mango_selector functions and a couple others so they hide how normalized selector fields actually look from other callers. There's only a couple of places where these normalized selectors need to be turned back into valid JSON, and the mango_util:join_keys() function turns the array keys back into binaries as needed.

There are a couple of places in the logic for choosing indexes for queries where we now have to parse fields to match the form they appear in in selectors, but I figure doing this once per query during index selection is better than doing it once per selector-field evaluation during index updates or filtering.

I assume the latter commit is the state we'd actually want to keep so I'm happy to squash all the other edits away. I also need to write proper commits messages; I'll tidy the history up once I know what should be kept in the history.

Related Issues or Pull Requests

Checklist

  • Code is written and works correctly
  • Changes are covered by tests
  • Any new configurable parameters are documented in rel/overlay/etc/default.ini
  • Documentation changes were made in the src/docs folder
  • Documentation changes were backported (separated PR) to affected branches

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