You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ignite.apache.org by "Aleksey Plekhanov (Jira)" <ji...@apache.org> on 2024/01/09 18:19:00 UTC

[jira] [Created] (IGNITE-21225) Redundant lambda object allocation in ClockPageReplacementFlags#setFlag

Aleksey Plekhanov created IGNITE-21225:
------------------------------------------

             Summary: Redundant lambda object allocation in ClockPageReplacementFlags#setFlag
                 Key: IGNITE-21225
                 URL: https://issues.apache.org/jira/browse/IGNITE-21225
             Project: Ignite
          Issue Type: Improvement
            Reporter: Aleksey Plekhanov
            Assignee: Aleksey Plekhanov


Every time we call {{ClockPageReplacementFlags#setFlag/clearFlag}} methods the new lambda object is created, since lambda is accessing the variable in enclosing scope. \{{ClockPageReplacementFlags#setFlag}} method called every time when page is modified, so, it's a relatevily hot method and we should avoid new object allocation here. 

Here is the test to show redundant allocations: 

 
{code:java}
/** */
@Test
public void testAllocation() {
    clockFlags = new ClockPageReplacementFlags(MAX_PAGES_CNT, region.address());
    int cnt = 1_000_000;

    ThreadMXBean bean = (ThreadMXBean)ManagementFactory.getThreadMXBean();

    // Warmup.
    clockFlags.setFlag(0);

    long allocated0 = bean.getThreadAllocatedBytes(Thread.currentThread().getId());

    for (int i = 0; i < cnt; i++)
        clockFlags.setFlag(i % MAX_PAGES_CNT);

    long allocated1 = bean.getThreadAllocatedBytes(Thread.currentThread().getId());

    assertTrue("Too many bytes allocated: " + (allocated1 - allocated0), allocated1 - allocated0 < cnt);
} {code}
 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)