-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize row_constructor Presto function (#1921)
Summary: row_constructor function used to copy data in cases when it was not necessary. Fix this by using `context->moveOrCopyResult`. Also, optimize RowVector::copy to copy one column at a time instead of one cell (value) at a time. Added a benchmark. Before: ``` ============================================================================ [...]unctions/prestosql/benchmarks/Row.cpp relative time/iter iters/s ============================================================================ noCopy 791.06us 1.26K copyMostlyFlat 4.28ms 233.54 copyMostlyConst 24.67ms 40.53 ``` After ``` ============================================================================ [...]unctions/prestosql/benchmarks/Row.cpp relative time/iter iters/s ============================================================================ noCopy 760.95us 1.31K copyMostlyFlat 1.69ms 592.85 copyMostlyConst 1.50ms 664.71 ``` Pull Request resolved: #1921 Reviewed By: kagamiori Differential Revision: D37624916 Pulled By: mbasmanova fbshipit-source-id: 868dbcc8ac8811fa14cb42b8966567130110eb52
- Loading branch information
1 parent
262fd65
commit e4ce5a6
Showing
6 changed files
with
185 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include <folly/Benchmark.h> | ||
#include "velox/functions/Macros.h" | ||
#include "velox/functions/Registerer.h" | ||
#include "velox/functions/lib/benchmarks/FunctionBenchmarkBase.h" | ||
#include "velox/functions/prestosql/registration/RegistrationFunctions.h" | ||
|
||
using namespace facebook::velox; | ||
using namespace facebook::velox::exec; | ||
|
||
namespace { | ||
|
||
class RowFunctionBenchmark : public functions::test::FunctionBenchmarkBase { | ||
public: | ||
RowFunctionBenchmark() : FunctionBenchmarkBase() { | ||
functions::prestosql::registerAllScalarFunctions(); | ||
} | ||
|
||
void run(const std::string& expr) { | ||
folly::BenchmarkSuspender suspender; | ||
vector_size_t size = 1'000; | ||
|
||
auto rowVector = vectorMaker_.rowVector({ | ||
vectorMaker_.flatVector<int64_t>(size, [](auto row) { return row; }), | ||
vectorMaker_.flatVector<double>( | ||
size, [](auto row) { return row * 0.1; }), | ||
}); | ||
|
||
auto exprSet = compileExpression(expr, rowVector->type()); | ||
suspender.dismiss(); | ||
|
||
int cnt = 0; | ||
for (auto i = 0; i < 100; i++) { | ||
cnt += evaluate(exprSet, rowVector)->size(); | ||
} | ||
folly::doNotOptimizeAway(cnt); | ||
} | ||
}; | ||
|
||
BENCHMARK(noCopy) { | ||
RowFunctionBenchmark benchmark; | ||
benchmark.run("row_constructor(c0, c1)"); | ||
} | ||
|
||
BENCHMARK(copyMostlyFlat) { | ||
RowFunctionBenchmark benchmark; | ||
benchmark.run( | ||
"if(c0 > 100, row_constructor(c0, c1), row_constructor(1, 0.1))"); | ||
} | ||
|
||
BENCHMARK(copyMostlyConst) { | ||
RowFunctionBenchmark benchmark; | ||
benchmark.run( | ||
"if(c0 < 100, row_constructor(c0, c1), row_constructor(1, 0.1))"); | ||
} | ||
|
||
} // namespace | ||
|
||
int main(int /*argc*/, char** /*argv*/) { | ||
folly::runBenchmarks(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters