Comments (6)
The 25-30% improvement is in line with what I expected for the box removal - very nice work!
from arrow-datafusion.
I'll make a PR some time today or tmr!
from arrow-datafusion.
Hi, I was curious about this and decided to test it out myself.
I first generated a flamegraph using flamegraph-rs (CARGO_PROFILE_BENCH_DEBUG=true cargo flamegraph --root --bench substr_index -- --bench
).
It seems like quite a lot of time is spent on malloc
, free
, and memmove
, as you noted in #9864 (comment).
A snippet of flamegraph.svg:
I then tested out a quick change to avoid the Box::new()
(at the expense of code duplication :D), and managed to get around -28% improvement!
% cargo bench --bench substr_index -- --baseline main
Compiling datafusion-functions v37.0.0 (/Users/kevin/git/arrow-datafusion/datafusion/functions)
Finished bench [optimized] target(s) in 56.31s
Running benches/substr_index.rs (target/release/deps/substr_index-bcc13e06371405f5)
substr_index_array_array_1000
time: [87.912 µs 88.197 µs 88.515 µs]
change: [-29.549% -28.257% -27.292%] (p = 0.00 < 0.05)
Performance has improved.
diff:
- let splitted: Box<dyn Iterator<Item = _>> = if n > 0 {
- Box::new(string.split(delimiter))
- } else {
- Box::new(string.rsplit(delimiter))
- };
let occurrences = usize::try_from(n.unsigned_abs()).unwrap_or(usize::MAX);
- // The length of the substring covered by substr_index.
- let length = splitted
- .take(occurrences) // at least 1 element, since n != 0
- .map(|s| s.len() + delimiter.len())
- .sum::<usize>()
- - delimiter.len();
+ let length;
+ if n > 0 {
+ let splitted = string.split(delimiter);
+ length = splitted
+ .take(occurrences)
+ .map(|s| s.len() + delimiter.len())
+ .sum::<usize>()
+ - delimiter.len();
+ } else {
+ let splitted = string.rsplit(delimiter);
+ length = splitted
+ .take(occurrences)
+ .map(|s| s.len() + delimiter.len())
+ .sum::<usize>()
+ - delimiter.len();
+ }
from arrow-datafusion.
🚀
from arrow-datafusion.
FYI @Omega359
from arrow-datafusion.
take
from arrow-datafusion.
Related Issues (20)
- [EPIC] A collection of improvements to optimize the speed of scalar functions
- DataFusion weekly project plan (Andrew Lamb) - April 22, 2024 HOT 3
- Remove ScalarFunction from datafusion.proto
- Move coalesce function from math to core HOT 2
- Remove ScalarFunctionDefinition
- CLI unable to execute queries with range(..) function HOT 1
- "Cannot infer common argument type for comparison operation Union..." HOT 5
- Error "entered unreachable code: NamedStructField should be rewritten in OperatorToFunction" after upgrade to 37 HOT 19
- `create table` fails in datafusion-cli with External error: Failed to convert path to URL: foo HOT 3
- Redirect existing docs from https://arrow.apache.org/ to https://datafusion.apache.org/ HOT 5
- Allow expr_to_sql unparsing with no quotes
- `select array_concat([])` panicked HOT 5
- ScalarUDF: Remove `supports_zero_argument` and avoid creating null array for empty args
- Support `Union` as a function HOT 5
- Create `Struct` table with explicit type and name HOT 2
- Stop copying LogicalPlan and Exprs in `OptimizeProjections`
- Stop copying LogicalPlan and Exprs in `TypeCoercion`
- Stop copying LogicalPlan and Exprs in `CommonSubexprEliminate` HOT 5
- Stop copying LogicalPlan and Exprs in `EliminateLimit` HOT 2
- Stop copying LogicalPlan and Exprs in `RewriteDisjunctivePredicate` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arrow-datafusion.