Skip to content
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

Code optimization suggestions #749

Open
noobyu6 opened this issue Jun 8, 2022 · 0 comments
Open

Code optimization suggestions #749

noobyu6 opened this issue Jun 8, 2022 · 0 comments

Comments

@noobyu6
Copy link

noobyu6 commented Jun 8, 2022

Hi,

I find that the private field metricsService at Line 36 in the file 'ninja/ninja-metrics/src/main/java/ninja/metrics/InstrumentedCache.java' on the develop branch is only assigned and used in the method InstrumentedCache. Therefore, this field can be removed from the class, and become a local variable in the method InstrumentedCache. Besides, for method init, the field metricsService can be converted to an input parameter.This transformation will normally reduce memory usage and improve readability of your code.I will be happy if this transformation is helpful.

private MetricsService metricsService; // line 36 this field can be replaced by local variable

InstrumentedCache(Cache cache, MetricsService metricsService) {
		this.underlyingCache = cache;
  	// MetricsService metricsService = metricsService;
    this.metricsService = metricsService;
  	// init(metricsService);
    init();
}
// private void init(MetricsService metricsService)
private void init() {
     MetricRegistry registry = metricsService.getMetricRegistry();

     hitCounter = registry.counter("ninja.cache.hits");
     missCounter = registry.counter("ninja.cache.miss");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant