Skip to content

[0.8.2a] Inserting ME disk items into AE2 allocates a CC computer ID and fsyncs on the main thread #856

Open

Description

@dargabi

Describe

Inserting the AP "ME disk" cell item (AEDiskCellItem) into AE2 storage stalls the server thread (~0.4 s per insert on our test machine, SSD-backed VM).

When AE2 inserts an item into a cell, BasicCellInventory.innerInsert asks StorageCells.getCellInventory(stack, null) whether the item is itself a cell. AEDiskHandler.getCellInventory then constructs a new AEDiskCellStorage, which calls AEDiskMedia.createDataMount → NonNegativeId.getOrCreate → ComputerCraftAPI.createUniqueNumberedSaveDir → IDAssigner.getNextId, which does a FileChannel.force (fsync). So every such check allocates a new CC computer ID and fsyncs on the main thread:

at sun.nio.ch.UnixFileDispatcherImpl.force0(Native Method)
at sun.nio.ch.FileChannelImpl.force(FileChannelImpl.java:525)
at dan200.computercraft.shared.util.IDAssigner.getNextId(IDAssigner.java:58)
at dan200.computercraft.shared.computer.core.ServerContext.getNextId(ServerContext.java:177)
at dan200.computercraft.impl.AbstractComputerCraftAPI.createUniqueNumberedSaveDir(AbstractComputerCraftAPI.java:71)
at dan200.computercraft.shared.util.NonNegativeId.getOrCreate(NonNegativeId.java:50)
at de.srendi.advancedperipherals.common.addons.ae2.disk.AEDiskMedia.createDataMount(AEDiskMedia.java:40)
at de.srendi.advancedperipherals.common.addons.ae2.disk.AEDiskCellStorage.<init>(AEDiskCellStorage.java:34)
at de.srendi.advancedperipherals.common.addons.ae2.disk.AEDiskHandler.getCellInventory(AEDiskHandler.java:27)
at appeng.api.storage.StorageCells.getCellInventory(StorageCells.java:119)
at appeng.me.cells.BasicCellInventory.innerInsert(BasicCellInventory.java:368)
at appeng.me.cells.BasicCellInventory.insert(BasicCellInventory.java:351)
at appeng.me.storage.NetworkStorage.insert(NetworkStorage.java:132)

The ID (and the save directory) should probably be created lazily, only when the disk is actually mounted by a computer, not when a cell inventory is merely constructed.

Steps to reproduce

  1. Insert ME disk items into an ME network repeatedly (e.g. with an import bus).
  2. Watch MSPT / take a spark profile: time is spent in IDAssigner.getNextId, and the computercraft ID counter keeps growing.

Multiplayer?

Yes

Version

1.21.1-0.8.2a (Latest 1.21.1)

Minecraft, Forge and maybe other related mods versions

Minecraft 1.21.1, NeoForge 21.1.264, AE2 19.2.18, CC:Tweaked 1.120.2

Activity

  1. zyxkad commented on Oct 22, 2026

    @zyxkad
    Collaborator

    For "keeps growing", do you mean you can insert the same disk repeatedly and grow the ID, or are you just getting disk from an inifite item source.

  2. dargabi commented on Oct 22, 2026

    @dargabi
    Author

    The same disk, not an infinite source. It only happens with blank disks (no disk ID yet).

    BasicCellInventory.innerInsert does itemKey.toStack() and passes that copy to StorageCells.getCellInventory(stack, null), so NonNegativeId.getOrCreate writes the new ID onto a throwaway stack. The key that actually gets stored is still a blank disk, so every insert of it (simulated ones too) allocates a fresh ID and fsyncs ids.json. Extract it and insert it again and it happens again.

    My repro was just a test harness inserting/extracting the same blank ME disk keys through the network storage in a loop. After a few runs computercraft/ids.json was at "disk": 31672. A disk that already has an ID doesn't bump the counter, it just builds the mount again.

  3. added a commit that references this issue on Oct 22, 2026
    b45d58d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    trespassingTrespassed issues that not using issue template.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions