Skip to content

Some tips when using the FAWE API

stefvanschie edited this page Nov 5, 2018 · 3 revisions

Performance tips when using the FAWE API:

1. Use the EditSessionBuilder and don't enable what you won't need.

See here.

2. Use the in built iterators whenever possible:

// Naive approach:
for (Vector pt : region) {
    BaseBlock block = editSession.getBlock(pt);
	// Do something
}
// Good approach:
// - Performs chunk preloading
for (Vector pt : new FastIterator(region, editSession)) {
    BaseBlock block = editSession.getBlock(pt);
	// Do something
}

The following classes will perform chunk preloading:

  • FastIterator
  • Fast2DIterator
  • FastChunkIterator
  • BreadFirstSearch
  • RegionVisitor

3. Use existing functions/operations instead of setting single blocks:

// Naive approach: single block changes
for (int x = 0; x <= 100; x++) {
    for (int z = 0; z <= 100; z++) {
        editSession.setBlock(x, 64, z, block);   
    }
}
// Good approach: 
//  - Does chunk preloading
//  - Performs on entire chunks rather than single blocks
//  - Does stuff in parallel
Region region = new CuboidRegion(new Vector(0, 64, 0), new Vector(100, 64, 100));
editSession.setBlocks(region, block);

4. Use the Sets/Collections that come with FAWE

// Naive approach: Storing individual positions
Set<Vector> positions = new HashSet<>(); // Then store some block positions here

// Good approach:
// - Faster and currently uses up to 800x less memory
positions = new BlockVectorSet(); 

5. Avoid calling a lot of the non block/biome related methods of AsyncWorld/Actor class:

FAWE has not optimized these at all to be used async. Consider using the TaskBuilder to break it up on the main thread instead.

This Wiki is for Legacy Versions (1.8 - 1.12.2). Check here for 1.13+ versions: https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/

Clone this wiki locally