You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -139,7 +141,7 @@ Operator | Condition looks like | Meaning
139
141
### compile
140
142
141
143
Compiles the given `selector`. The compiled selector can be passed to `apply`, `get`, and `set` instead of the original string.
142
-
If you intend to re-use a given selector for multiple operations, pre-compiling it gives a performance boost.
144
+
If you intend to re-use a given selector for multiple operations, pre-compiling it gives a significant performance boost.
143
145
144
146
The returned compiled selector also has methods `apply`, `get`, and `set`, so instead of calling `get(compiledSelector, obj)` you can
145
147
also do `compiledSelector.get(obj)`.
@@ -217,6 +219,24 @@ Otherwise, this function follows the same rules as [apply](#apply).
217
219
Returns **any** The new values of the selected properties. Unless collating, the length of the result gives an indication of
218
220
how many properties matched the selector.
219
221
222
+
## Performance considerations
223
+
224
+
There are a few other libraries that do the same thing, although none offer the features and expressive powers of this one. In particular, none allow using wildcards in selectors, conditions, or application of arbitrary functions - that's why I wrote this in the first place. That power comes at a price, though, and that price is speed. Below are benchmark results comparing `object-selectors` with some of the competitors.
1. If you only need to access simple nested properties in objects and performance is a concern, you should probably go with a different library.
238
+
2. Pre-compiling a repeatedly-used selector gives a performance gain of about factor 100.
239
+
220
240
## Security considerations
221
241
222
242
This package is based on a technique called *parsing expression grammar* (PEG) using [Peggy](https://peggyjs.org/) to parse and evaluate selectors. It does not use `eval`, and is therefore safe from the security concerns around code injection arising from it. This means it is safe to pass user content as selectors for read-only operations.
0 commit comments