Skip to content

Conversation

antonok-edm
Copy link
Collaborator

@antonok-edm antonok-edm commented Oct 1, 2025

supersedes #519

breaking API changes from this PR:

  • Added ResourceStorageBackend. This trait can be implemented to use customized storage backend logic, including sharing between multiple engines, caching from disk, ability to dynamically add/remove resources at runtime, collecting metrics, etc.
  • Added InMemoryResourceStorage as a port of the original ResourceStorage backend.
  • Removed Engine::add_resource. If you still need the ability to add individual resources at runtime, use a custom ResourceStorageBackend instead.
  • The regex-debug-info feature has been named to debug-info, as it now also enables a new API to get the size of the Engine's internal flatbuffer at runtime.

@antonok-edm antonok-edm self-assigned this Oct 1, 2025
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Rust Benchmark

Benchmark suite Current: 20c30b1 Previous: 1bfadd6 Ratio
rule-match-browserlike/brave-list 2224774239 ns/iter (± 8786760) 2157327098 ns/iter (± 15833464) 1.03
rule-match-first-request/brave-list 1109097 ns/iter (± 8618) 1067208 ns/iter (± 8765) 1.04
blocker_new/brave-list 151381104 ns/iter (± 1187448) 175128732 ns/iter (± 2762769) 0.86
blocker_new/brave-list-deserialize 20834838 ns/iter (± 35702) 73769476 ns/iter (± 854420) 0.28
memory-usage/brave-list-initial 10072539 ns/iter (± 3) 18344503 ns/iter (± 3) 0.55
memory-usage/brave-list-initial/max 64817658 ns/iter (± 3) 66961277 ns/iter (± 3) 0.97
memory-usage/brave-list-initial/alloc-count 1534723 ns/iter (± 3) 1616082 ns/iter (± 3) 0.95
memory-usage/brave-list-1000-requests 2516487 ns/iter (± 3) 2551890 ns/iter (± 3) 0.99
memory-usage/brave-list-1000-requests/alloc-count 66788 ns/iter (± 3) 68816 ns/iter (± 3) 0.97
url_cosmetic_resources/brave-list 204827 ns/iter (± 789) 189708 ns/iter (± 2713) 1.08
cosmetic-class-id-match/brave-list 15649919 ns/iter (± 4762393) 5166097 ns/iter (± 1523809) 3.03

This comment was automatically generated by workflow using github-action-benchmark.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Rust Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.10.

Benchmark suite Current: 20c30b1 Previous: 1bfadd6 Ratio
cosmetic-class-id-match/brave-list 15649919 ns/iter (± 4762393) 5166097 ns/iter (± 1523809) 3.03

This comment was automatically generated by workflow using github-action-benchmark.

@antonok-edm antonok-edm force-pushed the adjust-engine-public-api-2 branch from 4424d72 to 7a4eed6 Compare October 1, 2025 04:47
unfortunately this requires duplicating some definitions to support
additional `Send + Sync` trait bounds, since Rust does not natively
support conditional supertraits.
@antonok-edm antonok-edm force-pushed the adjust-engine-public-api-2 branch from 7a4eed6 to e454c54 Compare October 1, 2025 05:05
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

# Can be removed once https://github.com/actions/runner-images/pull/13076 is released
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's remove this to make the diff clear.
I've pushed the recent fixes from master to 0.11.x

// Since the beginning of flatbuffer data is aligned to that size,
// the alignment of the data must be a divisor of MIN_ALIGNMENT.
assert!(MIN_ALIGNMENT % std::mem::size_of::<T>() == 0);
assert!(MIN_ALIGNMENT.is_multiple_of(std::mem::size_of::<T>()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

the same, let's revert unrelated changes.

/// a custom [ResourceStorageBackend] if desired.
pub struct ResourceStorage {
#[cfg(not(feature = "single-thread"))]
backend: Box<dyn ResourceStorageBackend + Sync + Send>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

hm, I'm not strongly again Box<dyn ..> it makes the code less clear and may have some negative perf effect (if it's a hot path)

}
}

impl InMemoryResourceStorage {
Copy link
Collaborator

Choose a reason for hiding this comment

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

That code have major conflicts with master with #517.

/// Customizable backend for [Resource] storage.
/// Custom implementations could be used to enable (for example) sharing of resources between
/// multiple [crate::Engine]s, an on-disk backend, or special caching behavior.
pub trait ResourceStorageBackend {
Copy link
Collaborator

Choose a reason for hiding this comment

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

That trait looks internal to me. Can we don't make it public? I would say the best option is just to provide a few public methods to build ResourceStorage without exposing the other struct/traits

@atuchin-m
Copy link
Collaborator

Frankly, I can’t find the part that allow to shared the resources between multiple engines (the idea of my #519).
Maybe I'm missing something?

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.

3 participants