The execution time of blf.dimension is slow on Node Editor #104274
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#104274
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
System Information
Operating system: Windows 10
Graphics card: NVIDIA GeForce RTX 2060 SUPER
Blender Version
Broken: 3.5 alpha (Feb 1 2023,
345dded146
)Worked: 3.4 or before
Short description of error
This issue relates to https://developer.blender.org/T103210 as I reported before.
When we call Python API
blf.dimension
on Node Editor while zooming in/out , the execution time is much longer than other editors.The cause of issue comes from the slow execution time of
blf.dimension
while zooming in/out.Exact steps for others to reproduce the error
blf_dimension_slow_issue.blend
blf.dimension
Added subscriber: @nutti
Added subscribers: @Harley, @iss
Changed status from 'Needs Triage' to: 'Confirmed'
I was able to reproduce lag with 1 zoom event, but I assume this casues issues when string changes? But will confirm, since repro case is same as in previous report.
Added subscriber: @lichtwerk
@Harley : is this something you could look at?
Let me have this one for a bit, as I have been wanting to look into something that might be related. This one is a little different from #103210 (The execution time of blf.dimension is slow on Dope Sheet Editor) though...
When you zoom in/out in the Node Editor you see every intermediate step between where you started and where you end up. If it takes you half a second to zoom from a small size to a larger one you actually create 30 sizes in between.
Displaying text is very fast, but only because of caching. The rendering of each character (turning it into a little bitmap from curves) is quite slow, so we cache them for each size and style. We don't want you to be using memory to hold all those intermediate sizes when zooming so when you stop doing so we clear the caches. This means that immediately after you finish zooming we have to render again at the new size, but this is largely unnoticed because you aren't really doing anything at that time. But that can slow down your text measurement since those characters are not in the cache yet.
With #103210 (The execution time of blf.dimension is slow on Dope Sheet Editor) it was a matter of us clearing that cache unnecessarily. Zooming in Dope Sheet (and a few others) does not actually change the font size so there is no reason to clear that cache in that case, hence the solution here: {d11f3267cd93}
But zooming in the Node Editor(s) does change font size so the problem remains here.
Fairly certain that just clearing all glyph caches except for the last one (first in the list) would help you, be a performance improvement, and would have not negative effects that I can think of off the top of my head. But I'll need to make sure. And if I'm going to touch this it might be nice to get slightly fancier and keep the last one and any that match the current global (non-zoomed areas) size. Realistically I'd hope to look at this within the next couple of weeks with the goal to (hopefully) have an improvement for the 2.6 release.
@nutti:
Separately from fixing above, is there anything about your use can that I can help?
I'm mostly just curious what you are using
blf.dimension
for. I can imagine a few text-related things that would be better solved on my end for you. For an example off the top of my head if you wanted to know the ideal text size to fit a string within a certain target width, that would be something I could do faster and provide a python function for.@nutti - This is my idea, in case you able to compile and test.
@Harley
Thanks for taking the action.
I tried your patch, but the issue is much worse than before.
When I tried zoom in/out, Blender will freeze.
I use blf.dimension for checking the max height of the characters provided from the font.
This can be solved by executing blf.dimensions(0, string.printable)[0].
So, I can achieve my task instead if you provide API like blf.maximum_height_in_fontset(font_id).
But for what purpose?
I ask because the "max height provided in the font" is not the same as the height of the string.printable, which is something like "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+, -./:;<=>?@- [x]^_`{|}~".
You might want an "average" height of the font, to make sure that what you want to display will fit somewhere. But in that case you can just use the font size itself. The font size is also the size in pixels of the font's EM square at that size. It can be considered both the "nominal height" and "nominal width" of the font. If you just compare the result you are getting now with the size itself you will find a very close and linear relationship.
You might really want the height of that "printable" string, in which case you could probably take the height of "Hy" and be done in a fraction of the time, since you are doing so in a process that is clearing all the caches and therefore we must render all the glyphs in that string while the font size changes.
You might truly want the maximum height of the all the glyphs in the font, which is easy to get from the font but will likely be larger than what you are expecting because it will include characters outside that printable range. But you really need to consider the height of ⾼ as well?
Isn't that the length of the string since dimensions returns width then height?
@Harley
I need to use blf.dimension to get the actual rendering height because font_size is not the entire size for the actual rendering size.
string.printable does not cover all characters as you told, but string.printable is enough for the current purpose.
This matches my purpose. I only know the height of string.printable.
I'm not sure that specifying only "Hy" can get the maximum height of the string.printable.
Is this still works for non-default font?
Sorry, I mistook about the code.
The correct one is blf.dimensions(0, string.printable)- [x] as you pointed out.
Hmmm... you only get the "actual rendering height" of text if you measure that actual text, not a placeholder string like string.printable. So I'll assume that you are actually wanting the minimum height that can vertically contain any characters printed at a certain size? If you are attempting to guess the size of any UI elements note that they will be directly related to font size, not the measured height of any text. As in the header height of nodes and the line-spacing is not less if the text involved does not have ascenders or descenders, so the same amount whether the text is tall or short.
As mentioned the font size itself is directly and linearly-related to the measurement you want. If you find that is slightly too small for your use just add some wriggle room to it, as in use
font size * 1.04
or so and you will get the same value you are testing for now without any measuring.If you insist on measuring something, despite knowing it is not necessary, using all of sting.printable is not needed. You are only wanting the height so testing things like a "+" or "a" or "e" isn't adding anything. As mentioned earlier testing "Hy" will work for giving you a value for height of the alphanumeric characters (0-9,a-z,A-Z). If you want to include symbols then using something like "
|" will give you the maximum in string.printable. Personally I'd use "Hy
|" if I wasn't able to use font size directly.@Harley
Thanks for your instruction.
blf.dimensions(0, "Hy|")
works good without any lagging.I think this workaround is enough for my use case.
BTW, how do we conclude this issue?
If other API user does the similar thing, this issue needs to be discussed again.