Comments (21)
The parser can potentially be used for in-project optimization.
For example:
$intArray = $command->setSql('SELECT int_array FROM some_table')->queryScalar();
$parsedArray = (new ArrayParser())->parse($intArray);
$castArray = array_map('intval', $parsedArray);
instead of $castArray = $column->phpTypecast($intArray)
.
from db-pgsql.
Difference is so small and in different environments results may vary slightly. By logic property and static should be most performance, but in optimization most logic not always is most performance.
@Tigrov Little improve benchmark: Tigrov/yii3-benchmarks#1
My results:
Looks like directly use new
((new ArrayHelper())->parse()
) is most performance variant.
from db-pgsql.
yes, that's not a problem, it just resolves the value, it's not saved anywhere.
Why create instance every time? Many times - for each type casting.
But that's not a problem, as i tell you the object is not saved, it only resolves the value.
from db-pgsql.
yes, that's not a problem, it just resolves the value, it's not saved anywhere.
Why create instance every time? Many times - for each type casting.
But that's not a problem, as i tell you the object is not saved, it only resolves the value.
It's like widgets, they always create an object, and resolve its value to a string.
from db-pgsql.
Simple, if I create my own
db-pgsql
implementation, or just create thePGSQL NON-PDO
implementation, for example.Everything cannot be within the framework, there will be extensions.
It's will be extension of yiisoft/db
, not yiisoft/db-pgsql
. Array parser is not goal of this package, I don't think that yiisoft/db-pgsql
should provide it.
from db-pgsql.
can potentially be used for in-project optimization.
It's not optimisation, but the only way to get array from raw responses :(
from db-pgsql.
- Suggest make
ArrayParser
as internal. Users don't must use this class directly, it'sright?- For each type casting of string values created new instance of
ArrayParser
.Lines 107 to 112 in 56df5ac
It would be good prevent this behavior and create instance of
ArrayParser
once or makeArrayParser
methods static.
getArrayParser()
return new ArrayParser()
.
Always returns a new instance.
Line 155 in 56df5ac
from db-pgsql.
getArrayParser()
returnnew ArrayParser()
.
And creates new instance every time.
from db-pgsql.
getArrayParser()
returnnew ArrayParser()
.And creates new instance every time.
yes, that's not a problem, it just resolves the value, it's not saved anywhere.
from db-pgsql.
yes, that's not a problem, it just resolves the value, it's not saved anywhere.
Why create instance every time?
Many times - for each type casting.
from db-pgsql.
Should be a good optimization. Worth benchmarking.
from db-pgsql.
Btw array parser cannot be internal, Db
is an abstraction and you may need it for an extension.
from db-pgsql.
Btw array parser cannot be internal,
Db
is an abstraction and you may need it for an extension.
ArrayParser
used in specific implementation for PostgreSQL. When might it be needed somewhere else?
from db-pgsql.
Simple, if I create my own db-pgsql
implementation, or just create the PGSQL NON-PDO
implementation, for example.
Everything cannot be within the framework, there will be extensions.
from db-pgsql.
The parser can potentially be used for in-project optimization.
Agree. This is good case.
from db-pgsql.
It's not optimisation, but the only way to get array from raw responses :(
There is the second way where the parser is not used directly:
$castArray = $column->phpTypecast($rawIntArray);
But the first way will work almost 2 times faster.
from db-pgsql.
Benchmarks to compare current implementation with using property or static class:
https://github.com/Tigrov/yii3-benchmarks/blob/master/src/Benchmark/PgsqlBench.php
Results:
benchParseIntArrayCurrent...............I4 - Mo367.103μs (±0.61%)
benchParseIntArrayProperty..............I4 - Mo367.761μs (±0.90%)
benchParseIntArrayVar...................I4 - Mo369.223μs (±0.29%)
benchParseIntArrayNew...................I4 - Mo385.663μs (±0.31%)
benchParseIntArrayStatic................I4 - Mo372.307μs (±0.36%)
from db-pgsql.
Benchmarks to compare current implementation with using property or static class:
Optimization in PHP good work.
Seems, for cases when object use clear methods without side effects we can create object many times and it don't degradate performance.
from db-pgsql.
@vjik benchParseIntArrayNew
is 4.8% slower than benchParseIntArrayProperty
. Difference is not big, but noticeable.
from db-pgsql.
@vjik
benchParseIntArrayNew
is 4.8% slower thanbenchParseIntArrayProperty
. Difference is not big, but noticeable.
On my PC result little other:
Difference is so small.
from db-pgsql.
Changed ITEMS_COUNT to 1, results a slightly different:
benchParseIntArrayCurrent...............I4 - Mo0.825μs (±1.67%)
benchParseIntArrayProperty..............I4 - Mo0.765μs (±1.31%)
benchParseIntArrayVar...................R5 I4 - Mo0.793μs (±1.83%)
benchParseIntArrayNew...................R1 I3 - Mo0.790μs (±1.25%)
benchParseIntArrayStatic................R1 I4 - Mo0.982μs (±1.52%)
Looks like with property it works faster but the benchmark doesn't cover initialization of the property (from constructor, method or cache)
from db-pgsql.
Related Issues (18)
- How to after release HOT 1
- update links
- Dependabot can't resolve your PHP dependency files
- Support composite types HOT 3
- Add test for negative default values and parentheses
- Use stable version of `yiisoft/db` in CI
- Schema not loading with `PDO::ATTR_STRINGIFY_FETCHES => true`
- Prevent auto increment of primary key on duplicate values when `upsert()` HOT 3
- Wrong SQL with not unique index type HOT 2
- Add ability to alter column type without changing default value and null-state
- Upsert commands always builds a INSERT statemant for PostgreSQL Updatable Views HOT 4
- Add support for USING clause for alterColumn
- Trim git history
- Invalid index columns order
- Dependabot can't resolve your PHP dependency files
- May be need add compatible result for phptypes? HOT 1
- Wrong type for serial in migration
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 db-pgsql.