Skip to content

Conversation

graalvmbot
Copy link
Collaborator

This PR introduces a dual representation for MultiTypeState that uses a compact array for small sets and a BitSet for larger ones, reducing memory footprint when operating with small sets. The switch between representations is controlled by new configurable thresholds (MultiTypeStateArrayBitSetThreshold and MultiTypeStateArrayBitSetIntersectionSpeculationThreshold), Union, intersection, and subtraction now have fast array-based paths with optimistic merge strategies, falling back to BitSet when results exceed the threshold. Cross-representation operations are supported and optimized to avoid unnecessary conversions where possible. Memory reporting is updated to reflect the new representations and provide more accurate accounting.

The analysis time and total buid time does not seem to be impacted, which is in a way expected, since the TypeState operations form only a small part of the analysis phase workload at the moment (Most of the time is spend parsing and optimizing). However, the impact on allocation rate is significant for bigger images, see the result on Spring Petclinic below obtained with -H:+PrintTypeStateMemoryFootprint (~3x reduction).

Before:

                          Type	      Frequency	     Total Size
                EmptyTypeState	              1	             16
                 NullTypeState	              1	             16
    PrimitiveConstantTypeState	         414574	        9949776
         AnyPrimitiveTypeState	              1	             16
               SingleTypeState	        4512318	      108295632
             ConstantTypeState	        1137086	       27290064
      MultiTypeStateWithBitSet	        1920846	     5228386872
                         TOTAL	        7984827	     5373922392

With MultiTypeStateWithArray:

                          Type	      Frequency	     Total Size
                EmptyTypeState	              1	             16
                 NullTypeState	              1	             16
    PrimitiveConstantTypeState	         439922	       10558128
         AnyPrimitiveTypeState	              1	             16
               SingleTypeState	        4498336	      107960064
             ConstantTypeState	        1129578	       27109872
      MultiTypeStateWithBitSet	         495500	     1485887432
       MultiTypeStateWithArray	        1259448	       99756496
                         TOTAL	        7822787	     1731272040

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Sep 30, 2025
@graalvmbot graalvmbot force-pushed the d-kozak/GR-68465/small-size-typestate branch from 5794ace to a6c106b Compare September 30, 2025 15:53
@graalvmbot graalvmbot merged commit 857f947 into master Oct 2, 2025
13 checks passed
@graalvmbot graalvmbot deleted the d-kozak/GR-68465/small-size-typestate branch October 2, 2025 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants