CPU spikes with large variables

I’m running regression calculations in a CF worker and I’m seeing weird CPU spikes which eventually cause some request to fail. I have done some profiling on my code; using more features etc is not the reasons for these spikes since accessing the weights object is O(1). I might be completely wrong here, but I suspect that this is somehow related to memory allocation/deallocation.

This setup would be perfect unless P99.9 wouldn’t spike 4-6x higher (200-400ms) than p99.

What might be an explanation for the CPU spikes? Are there any actions I could take to prevent this weird behaviour? Can I profiler the worker in any way?

Any string object read into a variable is a parsed object, which is heavy on the CPU-time.

You might need to wait until Workers Unbound, so you can constantly use more CPU-time.

Until then you can only, reliably, use 50ms of CPU-time.


You could build a logging mechanism.
Do you use any dependencies that could influence?
I add to remove luxon, to a more efficient function.

Hey, I’m not sure what you mean here.

I don’t use any dependencies. But if there’s a way to do things more efficiently with a dependency I’m happy to hear your thoughts. CPU times etc are something which I don’t log myself, but CF does it for me.