-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make ArrayParser
internal and prevent multiple create instance of it
#297
Comments
Always returns a new instance. Line 155 in 56df5ac
|
And creates new instance every time. |
yes, that's not a problem, it just resolves the value, it's not saved anywhere. |
Why create instance every time? |
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. |
Should be a good optimization. Worth benchmarking. |
Btw array parser cannot be internal, |
|
Simple, if I create my own Everything cannot be within the framework, there will be extensions. |
It's will be extension of |
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 |
Agree. This is good case. |
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. |
Benchmarks to compare current implementation with using property or static class: https://github.com/Tigrov/yii3-benchmarks/blob/master/src/Benchmark/PgsqlBench.php Results:
|
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. |
@vjik |
On my PC result little other: Difference is so small. |
Changed ITEMS_COUNT to 1, results a slightly different:
Looks like with property it works faster but the benchmark doesn't cover initialization of the property (from constructor, method or cache) |
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 |
1) Suggest make(#297 (comment))ArrayParser
as internal. Users don't must use this class directly, it'sright?ArrayParser
.db-pgsql/src/ColumnSchema.php
Lines 107 to 112 in 56df5ac
It would be good prevent this behavior and create instance of
ArrayParser
once or makeArrayParser
methods static.Similar case: #303 (comment)
The text was updated successfully, but these errors were encountered: