#14043 closed enhancement (fixed)
Error-prone versus PMD on usage of short type
Reported by: | Don-vip | Owned by: | team |
---|---|---|---|
Priority: | normal | Milestone: | 16.12 |
Component: | Core | Version: | |
Keywords: | performance memory | Cc: | simon04, bastiK, michael2402, GerdP |
Description
r11294 addresses the new error-prone warning, thanks.
But it now raises warnings from PMD, see on SonarQube.
Java uses the short type to reduce memory usage, not to optimize calculation. On the contrary, the jvm does not has an arithmetic capabilities with the type short. So, the P-code must convert the short into int, then do the proper calculation and then again, convert int to short. So, use of the "short" type may have a great effect on memory usage.
One of the two warnings must be disabled or a new solution to be found. I have no idea what's the best solution between short and int. Do we have some profiling info?
Attachments (1)
Change History (14)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
We only have one short field (flags
).
Probably every JVM will tend to align the other fields to 4 Byte boundaries, so the 2 bytes we save using a short are used as padding for the next int field. We don't really gain anything from it. I'd prefer simply changing the flags to int. They should not be used directly by plugins.
Currently it is volatile to support checks like "is the object disabled or incomplete" sort of atomically. We should add a comment explaining this. isDisabledAndHidden
does it the wrong way by accessing the field twice.
comment:3 by , 8 years ago
I'd rather change OsmPrimitive.mappaintCacheIdx
to short. A saving of 4 bytes per primitive is worthwhile.
comment:5 by , 8 years ago
Please review the constants in OsmPrimitive
, if I got that right you should use 0x0001, 0x0002, 0x0004 etc.
The current code seems to be wrong.
follow-up: 10 comment:6 by , 8 years ago
I suggest to define all constants which are used with the field flags
in the same source.
comment:8 by , 8 years ago
You're right, rookie mistake... It did not change the warning in any way so I reverted the change. I'm going to build a new latest release to avoid data corruption.
comment:9 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I have disabled the PMD warning on SonarQube.
comment:10 by , 8 years ago
Replying to Gerd Petermann <gpetermann_muenchen@…>:
I suggest to define all constants which are used with the field
flags
in the same source.
Yes, can you make a patch? :)
by , 8 years ago
Attachment: | flags.patch added |
---|
I'd try to use constants, e.g.
protected static final short FLAG_MODIFIED = 0x0001;
instead of
protected static final short FLAG_MODIFIED = 1 << 0;