Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filterx allow stack based string wrappers #470

Merged

Conversation

bazsi
Copy link
Member

@bazsi bazsi commented Jan 24, 2025

This PR enables filterx code to create short-lived FilterXString instances on the stack.

Such instances

  • clone themselves on filterx_object_ref()
  • can only be unreferenced once
  • free_fn() is not called (this could be changed though and is up for debate)

The PR also contains a number of conversions from allocation based FilterXString instances to these, reducing the
total number of malloc() calls significantly for unset_empties(), parse_csv() and parse_kv()

@bazsi bazsi force-pushed the filterx-allow-stack-based-string-wrappers branch from 8f3cac8 to 6f96b60 Compare January 24, 2025 15:36
@alltilla alltilla self-requested a review January 28, 2025 10:16
Copy link
Member

@alltilla alltilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened a followup PR with a couple more stack allocated string usecases: #491

@alltilla
Copy link
Member

alltilla commented Feb 5, 2025

Thinking a bit more about concurrency, I don't even see how FilterXObjects can be accessed from multiple threads. I saw the atomic operations and my mind clicked to concurrency mode. Can you help me out about why we have atomic counters here?

I think if it is not necessary we either should not use atomic counters at all or we should write the code with the mindset that the refcounters can be changed concurrently, in which case my review comments stand.

@bazsi bazsi force-pushed the filterx-allow-stack-based-string-wrappers branch 2 times, most recently from bacdbc1 to 1ea3983 Compare February 6, 2025 19:33
@alltilla alltilla force-pushed the filterx-allow-stack-based-string-wrappers branch from 1ea3983 to f10f3fc Compare February 7, 2025 12:18
@alltilla
Copy link
Member

alltilla commented Feb 7, 2025

@bazsi rebased to main to include the #495 fix.

bazsi added 10 commits February 7, 2025 13:25
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
…ecast

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
…BJECT_REFCOUNT_FROZEN

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Instances of strings that are only used once for a brief period
can be allocated on the stack to reduce malloc() calls. This is especially
useful when iterating over a lot of FilterXString instances, most of
which is imediately dropped away.

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Clarify the races involved and also trigger an abort on use-after-free.

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
@bazsi bazsi force-pushed the filterx-allow-stack-based-string-wrappers branch from f10f3fc to 6b3afc7 Compare February 7, 2025 12:25
@alltilla alltilla merged commit cbaba64 into axoflow:main Feb 7, 2025
22 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