PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Written By
Views

Ktheme Performance Improvements

Ktheme Performance Improvements

test8.png Ktheme is a automation tool I created to apply color themes to applications based on a image. it also applies the image as wallpaper and if multiple monitor exists it will crop the image and apply it to the correct monitor so it looks like it's seemless. This is not present in my linux distro so I had to make it myself. It also applies to spotify/discord, the kde theme colors and many more smaller applications.

Since it's created with python it has some inherit performance blocks. Previously I had improved some of the more costing functions by using Nim which has a great python interop with Nimporter and Nimpy

Offloading to Nim really improved speed of iterating over stuff. But I realized there was a lot of other performance blocks. While timing different parts I found out that one call was extremely slow. -> list(im.getdata()) This call was to create a list from the pixeldata from the image.

While figuring out how to create to that call faster I found numpy.array(). Problem with that was that it didn't translate well into the Nim function that was processing it. So to mitigate that issue I had to convert it back to a list.

im = Image.open(path)
pixels = list(im.getdata())
#this takes 18s on a 15360x8640

im = Image.open(path)
px = np.array(im)
px.reshape((px.shape[0]*px.shape[1]), px.shape[2])
px = [*map(lambda x: (x[0], x[1], x[2]), px)]
#this takes 4s on a 15360x8640

There was 2 places this was used and if image was large it would halt for soooo long. So this was a major improvement to speed.

Secondly I realized most of my functions that applied the theme to different applications could be run in parallel since they didn't depend on each other.

So after adding the multiprocessing library i was able to cut even more seconds away.

Results

# 15360x8640
(7m, I got bored waiting so I canceled it) -> 58s
# 1920x1200
15s -> 7s
# 8192 × 5794
44s -> 10s

since my monitor setup has a total size of 5600x1920 most of the images I'm using is between the 1920 to 8192 size and that would be a 100% -> 400% improvement in speed

Comments (0)

loading comments