Will java class size affect application performance

I am using a swing based application where I am using JTable . I used DefaultCellEditor for one of the columns, which requires a selection with a list. But DefaultCellEditor has many methods that I do not need. Therefore, I wrote a special CellEditor, expanding AbstractCellEditor , where I applied only the necessary methods. My question is:

(in general), if we have a class, and if we do not require all the methods of this class, is it good to use it or is it useful to write our own class, where we implement only those methods that we need? and

with the help of a user class will the application performance (memory) be improved or will it remain the same as the class that has all the methods?

Any help would be appreciated.

+6
source share
3 answers

Unless you have good reason to believe that nothing in the application, including the JDK itself, uses DefaultCellEditor, , you are almost certainly wasting your time making things worse.

You also need to consider that you could save maybe 100 thousand code in extreme cases when regular JVMS use about a gigabyte to execute. Thus, you may have saved 0.01% of the code space. This is an inefficient use of your time. The correct procedure is to check and measure where the bottlenecks of time and space actually occur, after the fact. Programmers are notoriously predicting these things.

+15
source

The code (actual bytecode) for this class is loaded only once in the PermGen memory area, regardless of how many instances of this type you create.

I would not accept this code, since you are already duplicating functionality, and you are not adding functionality to AbstractCellEditor , you are overriding the code in DefaultCellEditor , which Oracle (or the Sun) has already (hopefully) tested.

As EJP said, it’s not worth the time or opportunity to introduce errors.

+3
source

If you create a custom class that contains fewer member objects, then the memory size will be lower. The number of methods will not affect the size of objects, but only the size of the class.

In general, I will not prematurely optimize if you do not determine that you really have a problem (i.e. if you have thousands of object instances and analysis of heap / garbage collector logs, then it turns out that you are tricking memory and / or have frequent collections of old space), because additional code means:

  • Extra service (you need to make sure your custom CellEditor not an error)
  • Extra effort to write custom code
  • Extra effort when testing custom code

AFAIK, a CellEditor is created as needed, so you won’t save a lot of memory anyway.

+1
source

Source: https://habr.com/ru/post/925644/


All Articles