Comments (14)
@easydowork could you provide the benchmark without cache vs few cache types? cheers
I have never used a benchmark before, I will try it.
from yii2.
how is anyone taking such issues seriously? Please, stop with nonsense issues
from yii2.
Is there a significant performance boost with a cache in here?
from yii2.
Is there a significant performance boost with a cache in here?
$t1 = microtime(true);
$className = Yii::$app->cache->getOrSet([Yii::$app->id,Yii::getAlias('@app'),'createControllerByID',$id],function () use($id){
$pos = strrpos($id, '/');
if ($pos === false) {
$prefix = '';
$className = $id;
} else {
$prefix = substr($id, 0, $pos + 1);
$className = substr($id, $pos + 1);
}
if ($this->isIncorrectClassNameOrPrefix($className, $prefix)) {
return null;
}
$className = preg_replace_callback('%-([a-z0-9_])%i', function ($matches) {
return ucfirst($matches[1]);
}, ucfirst($className)) . 'Controller';
$className = ltrim($this->controllerNamespace . '\\' . str_replace('/', '\\', $prefix) . $className, '\\');
if (strpos($className, '-') !== false || !class_exists($className)) {
return null;
}
return $className;
});
$t2 = microtime(true);
print_r(bcsub($t2,$t1,4));echo PHP_EOL;exit;
The performance difference between using cache and not using cache is about 15 times, as regular expressions are not used anymore
from yii2.
Let's go for it. Could you prepare PR?
from yii2.
The performance difference between using cache and not using cache is about 15 times,
Do you have an actual benchmark? What is so slow in this method that would justify using cache? I tested preg_replace_callback()
only and it is at least twice as fast as reading cache using FileCache
.
from yii2.
The performance difference between using cache and not using cache is about 15 times,
Do you have an actual benchmark? What is so slow in this method that would justify using cache? I tested
preg_replace_callback()
only and it is at least twice as fast as reading cache usingFileCache
.
I was just a simple test, calculating the running time, and indeed there is such a significant difference. Using cache does not require additional checks and judgments
from yii2.
Using cache does not require additional checks and judgments
Cache has its own overhead, it is not always worth to cache some calculation, sometimes retrieving cached value is slower than calculating it. And it has some other disadvantages: cache takes resources (memory or disk space) and it can be outdated.
from yii2.
I can see that time test is taking cache handling into the consideration, that is why I asked for an implementation proposal. We should double check the actual gain since there are some doubts.
from yii2.
@easydowork could you provide the benchmark without cache vs few cache types? cheers
from yii2.
@easydowork, thanks for taking time to make PR.
Can you provide the benchmark with and without #20115 so that we can make comparison?
That would easily help decide if we should consider merge or not, based on merits
from yii2.
@Webkadabra who exactly and which comment are you responding to?
from yii2.
I will do a simple test, using the microtime (true) function to calculate the difference, and replacing preg_replace_callback with cache in the createControllerByID function does indeed improve the calculation time, but it increases the complexity and instability risk of the system. So I gave up.
from yii2.
with cache in the createControllerByID function does indeed improve the calculation time, but it increases the complexity and instability risk of the system. So I gave up.
I'm going to close it then. Since it seems to add complexity that isn't worthy it. Correct me If I understood you wrong!
from yii2.
Related Issues (20)
- Abstract type is incorrect for primary keys while loading column schema HOT 7
- Improper loading of column schema for PgSQL HOT 3
- MaskedInput HOT 4
- Data providers perform unnecessary COUNT queries that negatively affect performance HOT 18
- foreach() argument must be of type array|object, bool given HOT 1
- Bug: DataProvider total count is incorrect HOT 4
- Where is a 2.0.50.1 bugfix release? HOT 2
- ActiveForm: Validation delay is applied in non `validateOnType` scenarios
- update links
- update to 2.0.50 error HOT 1
- BC break: \yii\data\ActiveDataProvider throws yii\base\InvalidConfigException depending on array config keys order HOT 1
- SqlDataProvider makes error, if used with pagination
- Model:loadMultiple() method not working in update records HOT 1
- Regression in FileValidator since Yii 2.0.50 when validating required files HOT 4
- Model modification data failed HOT 3
- BaseActiveRecord save method - php docs do not state possible throwing of exception HOT 2
- CompositeAuth does not respect the $user of authMehods HOT 12
- ActiveDataProvider::prepareModels: wrong queries when using union subqueries and pagination HOT 7
- fileCache expire not set HOT 2
- Auto calculated width in GridView columns doesn't take care of placeholder text in search columns HOT 8
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 yii2.