branlwyd / bdcpu16

DCPU-16 simulator based on version 1.7 of the DCPU-16 specification. See http://dcpu.com/.
0 stars 0 forks source link

Core: do not call Device.step() on every device for every CPU step #17

Closed branlwyd closed 11 years ago

branlwyd commented 11 years ago

See comment below.

Currently, every call to Cpu.step() loops through the attached hardware and notifies each device that some cycles have elapsed. While this allows for accurate hardware simulation, this loop is slowing us down (I think).

branlwyd commented 11 years ago

This may not be such a good idea now that the debugger is in & depends on the cyclesElapsed() call. If cyclesElapsed() was called only once every n steps, stepping the debugger would actually skip n instructions!

branlwyd commented 11 years ago

The device step loop is a huge performance issue. But definietely don't do the original suggestion. Instead, experiment with the following change:

Can use a simple priority queue-like structure. Most hardware doesn't refresh more than every 1/60 of a second = ~1666 cycles; on fast (no wakeups) path I am trading the loop over every device for a single addition.

Difficulty in handling keyboard, since it's hanging out on another thread and there's no pattern to when its interrupts occur. Can schedule a fast-ish timer when interrupts are enabled--no perf loss when they're disabled.

branlwyd commented 11 years ago

Switched to a scheduled-wakeup model in e204532db8c51824b576feaea4e2b907f2da37c9. Closing.