DrPepper Problem

From Moondust Wiki
Jump to navigation Jump to search
English Русский

Dr. Pepper Problem - is the major performance issue of the Super Mario Bros. X game caused by disabled blocks indexing system once any layer got moved horizontally. The problem was initially investigated and described by Rednaxela in May 2018, and later, independently, was researched by Wohlstand in May 2021, while debugging TheXTech using the Orange Pi PC single-board computer.

Title

The problem was named after the "Dr. Pepper Pyramid" level from the episode "2k15 Summer Takeover" for SMBX, where the problem was actually investigated.

Description

Problem absence, the FPS is close to normal
DrPepper problem in action, FPS got slowed down because of 15k+ objects at the processing loop

The problem often gets be reproduced on old or slow user devices (for example, mobile phones, single-board computers, or just old hardware). The reason for this problem is hidden in the block indexing algorithm. Performance slowdown happens once the indexed search of blocks gets to be disabled once any layer got moved horizontally.

Boosted search blocks algorithm in the SMBX

This algorithm requires all blocks to be sorted in an array and grouped by X position and then sorted by Y within the selected group. The indices of the beginning and end of the boundaries are entered into two arrays, whose indices are equivalent to the quotient X and 32. During the search for blocks, the left and right boundaries along X are selected, and then the blocks are searched in the selected range and possible collisions are checked. This algorithm is ineffective in vertical sections because all blocks along the entire height fall into the loop.

Slowdown occurs

Since the game implements a system of moving groups (layers) of elements, include blocks, it became necessary to freely move blocks around the scene without damaging the ability to search for moved blocks. When blocks got moved vertically (along Y), there is no problem, since all blocks are still in the same group X. As soon as the group starts to move horizontally (that is, along X), it became necessary to re-sort the array of blocks and update the index tables, otherwise, the blocks will no longer be searchable. However, the author of the SMBX game, instead of implementing safe re-sorting of an array of blocks after moving a group, completely disables index search as soon as any moving layer has moved any of the blocks along X, thereby triggering the named "Dr. Pepper problem". Because of this, the game starts each physics and rendering cycle to process all the blocks that are on the level, significantly increasing the load. With a powerful processor, the in-game performance slowdown remains unnoticeable. However, in the case of single-board computers, mobile devices, and old hardware, the problem is causing a very severe visible slowdown in the entire gameplay.

Solution

To completely resolve the problem, the ds-sloth developer made the new block indexing system using the quad-tree that allows the free movement of any blocks without the necessity of any array resorting.

Interesting fact

Redigit had already noticed this problem on his SMBX 1.2 beta announcement:[1]

Read This, It's Important: Using layers to move blocks horizontally (left or right) disables the single best collision detection optimization in the game. You WILL have slow downs if you do this in a level with a large number of blocks and NPCs. Don't say I didn't warn you.

However, with time, this was been forgotten, and people didn't know about it.

Engines affected by the problem

References