Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Performance issue with global constants?

andreas-de
Explorer
0 Likes
2,483

Hello,

I prefer to define constants as attributes in a class interface for cross program usage. Now, someone said, global constants have an negative performance issue. Argumentation is something like "The constant value needs to be copied from global stack to local program stack".

Looking at 'Declaration of Data Types and Constants' (SAP ABAP docu) I think it should be ok like I usual do.

Can you confirm performance issues with global ABAP OO constants? Is this a real issue which the end user will realize at a normal transcation? Or is this more a academic topic?


Thanks in advance

1 ACCEPTED SOLUTION
Read only

sharanjee_186716
Product and Topic Expert
Product and Topic Expert
2,192

Use Interface Constants instead of Class. There is no performance issues with global constant.

9 REPLIES 9
Read only

holger_janz
Product and Topic Expert
Product and Topic Expert
2,192

No, there aren't performance issues with global constants. #fairytale

Read only

pokrakam
Active Contributor
2,192

This is possibly an issue with loading a static class into the internal session memory, which - unlike instances - is not unloaded by the garbage collector. I think this may be what your colleague might be referring to.

This is one argument for using interface vs class constants, as interfaces contain no executable code and interface constants are (probably) evaluated at compile time. Personally I use interface constants as well for this reason.

Read only

pokrakam
Active Contributor
0 Likes
2,192

...which is exactly the bit I'm unsure about: Since interfaces have no executable code, are they considered bytecode or processed in their entirety at compile-time for scenarios such as this? It's theoretically possible, but, ABAP being ABAP, theory means little 🙂

Read only

0 Likes
2,192

I guess documentation is due for another update. 🙂

But seriously - are we even talking any significant potential performance impact here?

Read only

pokrakam
Active Contributor
2,192

Could have a significant impact for large scale compute-intensive applications such as cosmological dark matter distribution modelling, or playing chess against another computer.

In other words, mostly academic.

Read only

retired_member
Product and Topic Expert
Product and Topic Expert
0 Likes
2,192

PXA also buffers shared resources like the values of constants.

Read only

sharanjee_186716
Product and Topic Expert
Product and Topic Expert
2,193

Use Interface Constants instead of Class. There is no performance issues with global constant.

Read only

2,192

But classes allow unit tests. Can make sense even for constants (checking values against external ressources).