# Custom fonts slowing down my program

**URL:** <https://discourse.processing.org/t/custom-fonts-slowing-down-my-program/7081>\
**Category:** Coding Questions\
**Created:** [January 1, 2019, 11:23pm UTC](https://discourse.processing.org/t/custom-fonts-slowing-down-my-program/7081 "2019-01-01T23:23:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kazuya\_Yoshimisu](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@Kazuya\_Yoshimisu](https://discourse.processing.org/u/Kazuya_Yoshimisu)\
**Post date:** [January 1, 2019, 11:23pm UTC](https://discourse.processing.org/t/custom-fonts-slowing-down-my-program/7081/1 "2019-01-01T23:23:49Z")

</div>

Hello everyone,

So I’m making a project in p5.js which aim to reproduce the Matrix rain code effect.  
It ran pretty smooth until I decided to load a custom font.  
When I did, my framerate dropped considerably. And it’s the case for every custom font that I try to load (only when I use the loadFont function; if I use textFont and some default font it doesn’t seem to slow down)

Of course, I use the loadFont function in the preload function, and textFont in setup, so I don’t know if this is a known thing ? How could I avoid this ?

Thanks !

---

<div class="post-metadata">

**Author:** ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)\
**Post date:** [January 2, 2019, 12:25am UTC](https://discourse.processing.org/t/custom-fonts-slowing-down-my-program/7081/2 "2019-01-02T00:25:39Z")

</div>

I can’t think of a reason on why it would slow down. Could you please provide MVE(Minimum Viable Example) of the slow-down? Some code?

---

<div class="post-metadata">

**Author:** ![Kazuya\_Yoshimisu](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@Kazuya\_Yoshimisu](https://discourse.processing.org/u/Kazuya_Yoshimisu)\
**Post date:** [January 2, 2019, 1:03am UTC](https://discourse.processing.org/t/custom-fonts-slowing-down-my-program/7081/3 "2019-01-02T01:03:45Z")

</div>

For instance this code prints in the console values around 40-50ms, but when I comment out the line textFont(font); the values are around 10-20ms

```auto
var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789$+-*/÷=%\"'#&_(),.;:?!\\|{}<>[]^~ "
var font;

var spacing_width = 10;
var spacing_height = 20;

function preload() {
	font = loadFont('matrix_font.otf');
}

function setup() {
  createCanvas(window.innerWidth, window.innerHeight);
  frameRate(60);
  background(0);

  textFont(font);
  fill(255)
}

var lastUpdate;

function draw() 
{
  background(0);

  var timeSinceLastUpdate = new Date().getTime() - lastUpdate;
  print(timeSinceLastUpdate + "ms")
  lastUpdate = new Date().getTime();

  for(var i = 0; i < 40; i++)
  	for(var j = 0; j < 40; j++)
  	  text(characters[int(random(0, characters.length))], j * spacing_width, i * spacing_height)
}

```

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [January 2, 2019, 5:27pm UTC](https://discourse.processing.org/t/custom-fonts-slowing-down-my-program/7081/4 "2019-01-02T17:27:01Z")

</div>

Please link between crossposts. This question has also been posted here:

> <https://stackoverflow.com/questions/54010559/why-are-custom-fonts-slowing-down-my-program>

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [January 15, 2019, 7:57pm UTC](https://discourse.processing.org/t/custom-fonts-slowing-down-my-program/7081/5 "2019-01-15T19:57:05Z")

</div>

The stackoverflow also links to this p5.js github issue, which profiles the problem:

> <https://github.com/processing/p5.js/issues/3435>
