[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Improving performance of Lua on low-end systems
- From: Rena <hyperhacker@...>
- Date: Tue, 28 Oct 2014 17:31:57 -0400
On Tue, Oct 28, 2014 at 5:18 AM, KHMan <keinhong@gmail.com> wrote:
> On 10/28/2014 12:15 PM, Coda Highland wrote:
>
>> On Mon, Oct 27, 2014 at 9:02 PM, Rena wrote:
>>>
>>> I'm using Lua in a homebrew PSP app (not PS Vita, the original PSP
>>> with 32-64MB RAM and ~333mhz MIPS CPU) and finding performance has
>>> dropped rather sharply (compared to original app which didn't use
>>> Lua). It's using Lua 5.2, though compiling another version for it
>>> wouldn't be out of the question. The main loop isn't doing a lot of
>>> work, but makes multiple calls to C functions (read the button states,
>>> draw things on the screen, read the clock). Does anyone have advice to
>>> improve performance?
>>
>>
>> I pinged a friend of mine who used to do a lot of PSP development. He
>> recommends making sure you're caching aggressively -- for example,
>> checking the button state more than once per frame is meaningless.
>>
>> Myself, I'd suggest seeing if LuaJIT's MIPS port will work, even with
>> just the interpreter. It might perform better.
>
>
> Perhaps JIT is the best solution. There is a R4000 reference manual on the
> internet, it's pretty enlightening.
>
> The R4000 on the PSP is said to have 16KB ICache and 16KB DCache. No level 2
> unfortunately. Even worse for modern workloads, both level 1 caches are
> direct-mapped. An interpreter will churn the caches a lot more.
>
> Also, the FPU mentioned in the manual has significantly higher latencies for
> some operations versus modern FPUs, e.g. ADD and SUB for floating point have
> a minimum latency of 4. Bad news for the default Lua number type.
>
> Can't find any detailed processor data for the PSP R4000, but the original
> R4000 is purportedly a 1991 thing (PSP is 2004). No idea whether Sony made
> changes, maybe not, so then it will be 1991 technology. It will look pretty
> weak compared to modern processors...
>
> --
> Cheers,
> Kein-Hong Man (esq.)
> Kuala Lumpur, Malaysia
>
>
Right, I forgot to mention, I'm using float for lua_Number type.
(AFAIK, the PSP doesn't have hardware support for double, so it's
quite slow.) I could probably get a decent boost by using an integer
type instead, but I'm not sure how that could work (no ability to
handle fractions?) - maybe this would be a good use of Lua 5.3?
I think the PSP CPU has some enhancements compared to the original
design (added vector instructions?) but I'm not certain. That might be
worth looking into.
Someone mentioned that calling across the language boundary (C to Lua
and vice-versa) is expensive? (I could never remember if that applies
to Lua, LuaJIT, or both.) So it might be worth trying to reduce C
calls?
I'll also look into redesigning the app so that Lua isn't involved as
much (much as I hate to do it!); that probably would give a decent
boost, but I've been hoping to avoid it because it trades off
flexibility.
Thanks for the advice, folks, and keep it coming!
--
Sent from my Game Boy.