janjongboom / janpatch

JojoDiff Alternative Patch library - portable C library for memory-efficient binary patching
Other
133 stars 25 forks source link

added wrapper for optimisation purposes #3

Closed marcusjzw closed 6 years ago

marcusjzw commented 6 years ago

G'day,

We have been utilising your JANPatch implementation for internal purposes in a project.

We encountered an issue with runtime speeds when deploying JANPatch onto our target embedded device, which led us to check CPU usage using KCacheGrind. It took 3 minutes to apply a 256B patch to produce a 3kB target file. A point of optimisation we uncovered was the elimination of ftell() and the spoofing of fseek() through an internal counter mechanism.

We have developed a wrapper to achieve this functionality. Consequently, our performance has improved 26.6x in terms of speed on the target device.

Feel free to review the changes proposed.

Cheers

janjongboom commented 6 years ago

@celesti0n Thanks! Will review as soon as possible. Please don't remove the #ifdef wrappers around the JANPATCH_STREAM declaration; they're needed for non-POSIX systems.

janjongboom commented 6 years ago

@celesti0n Which file system are you using? If your file system has very slow ftell / fseek commands it might be better to implement the internal counter as part of your program (like I do for raw block device access here) rather than putting this in core janpatch.

janjongboom commented 6 years ago

Alright, so I can indeed reproduce this on MacOS as well. I have https://github.com/janjongboom/janpatch/pull/6 as a follow-up to this issue. I see the same performance with both patches, so let's continue conversation there. Thanks a lot!