TASEmulators / TASEmulators/BizHawk

Make ReadByteRange use a wrapper class instead of copying the entire thing into a new byte array

Open
#2,927 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

App: EmuHawk Meta re: APIHawk Request: Feature/Enhancement
Dominant language
C#
Stars
2.8k
Forks
468
PR merge metrics
No merged PRs in 30d

Description

Current code: https://github.com/TASEmulators/BizHawk/blob/3ea71a2dda118b0cadd43c75ee6a577d01f5c6a9/src/BizHawk.Client.Common/Api/Classes/MemoryApi.cs#L246-L256

when a readbyterange is used every frame for large amounts, this can greatly reduce performance (60fps to 2fps). This is partially due to the memory allocation every frame, but also because all the data is copied over. It would likely be more efficient to read them when they are accessed. This has the drawback of not accounting for bytes written to that range since reading, so maybe add a nullable parameter to specify whether to lazy-load the range.

The reason for this request is that I often have to access memory quite often in a single frame, resulting in a ~20fps decrease just from all the memory.read_XXX calls, and having it available faster would be nice.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/BizHawk.Client.Common/Api/Classes/MemoryApi.cs at lines 246-256, where ReadByteRange currently creates and copies a byte array. Compare the proposed wrapper and lazy-loading behavior, including how writes after the read should be handled. Done means reducing per-frame allocation and copying without changing the expected ReadByteRange behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.