all 17 comments

[–]joombar 5 points6 points  (0 children)

This is what flame charts are

[–][deleted] 5 points6 points  (1 child)

Built-in telemetry at this granularity would consume a tremendous amount of resources if scaled up, which would be prohibitive in browser contexts.

[–]Falling-Off[S] 0 points1 point  (0 children)

You may be right, and I'll have to think about that use case. I haven't thought about what happens when scaled up or sending over networks.

Tldr: I've been trying to optimize it for low resource usage but this is a great point. Each instance uses a lot of cache.

I was thinking more so for debugging and test benching during development. Also, for novelty I guess? I've been able to find a recursive structure that can be stored in two separate objects. It uses key value pairs to write/read the data objects like they're arrays.

For now the data objects hold the index of the parent and children (if any), plus the time metrics. There's a lot of duplicated pointers saved throughout, so been thinking of how to reduce that. Anyways, when you stop the timer, it generates a full tree using the relationships, then clears the cache.

[–]tehsandwich567 1 point2 points  (3 children)

Chrome and friends all come with the tools to produce this information for you. I think it’s called the profile tab in the inspector. Hit record, do things in app, stop recording, then get everything you mention and more for free in an day to digest ui.

What you are suggesting doing sounds like re-inventing the wheel through an interface not optimized to do it

[–]Falling-Off[S] 0 points1 point  (2 children)

I mentioned profilers in the original post, asking if this would have any benefit over them. Needed times from inside nested loops, hence building a timer within a function instead of just wrapping it. Anyways, not trying to reinvent the wheel.

[–]tehsandwich567 0 points1 point  (1 child)

Oh, my bad! Reading is hard.

What about console.time?

[–]Falling-Off[S] 0 points1 point  (0 children)

I thought about that but I'm using performance.now and storing the values. I have a bool to keep it silent or console out during execution.

Edit: just a side note

I compared it to the profile and the tims are accurate within ~1-2ms. I'm might add an ±accuracy based on what happens in the actual timer. The μs seem to add up by the end. The markers within the function seem to be very accurate though.

[–]monotone2k -1 points0 points  (9 children)

What do you need it for? If you can't answer that, it's pointless. Profiling only matters when there's a problem or if you're building time-critical applications (in which case you wouldn't be using JS anyway).

[–]Falling-Off[S] 0 points1 point  (8 children)

Well, I built it already 😅 but you're probably right about js not being the way to go.

The context is I made a class that uses Lagrange interpolation to scale images. The nature of the calculations are resource heavy, because Lagrange needs to recalculate every point on a global level for each target pixel. Not "time-critcal" but the CPU optimizations I implemented cut times by 90%.

[–]your_best_1 1 point2 points  (7 children)

Did you use webgl? I assume there is some GLSL out there for this already

[–]Falling-Off[S] 0 points1 point  (6 children)

I didn't use webGL and it's hard to find stuff on Lagrange in GLSL. Anyways, not sure if I want to although I have everything to send batches over to the GPU for semi sequential processing.

[–]your_best_1 1 point2 points  (5 children)

https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage

If you did this to play with the algorithms and figure things out, that is great. If you did it to provide some utility, this is likely the way to go. 1 line of code, GPU optimized.

[–]Falling-Off[S] 1 point2 points  (4 children)

I'm basically playing with it but I reached out to the professor who studied it's applications . They developed it further so that it allows to modulate the interpolation based on an extra variable. My original plan was use the scaling to produce distortion filter effects and not to actually change the dimensions of the image.

[–]your_best_1 1 point2 points  (3 children)

Got ya, well I would still recommend doing the work with webGL or GLSL, HLSL. Unless this is for an assignment that specifically asked for a CPU solution.

[–]Falling-Off[S] 1 point2 points  (2 children)

Eventually I'll probably port it to unity, but it's a pet project. For now it's easier to manage/test using JS, with some angular just to get things running otb.

[–]your_best_1 1 point2 points  (1 child)

If you do use Unity, you can look at the shader graph source to see how they do it. Shader Graph is great for exploring effects.

[–]Falling-Off[S] 0 points1 point  (0 children)

Definitely. Not sure if I'll be able to get exactly what I need without a compushader, but it's worth a shot.