• fzyzcjy's avatar
    Show error message in release mode when box is not laid out without losing performance (#126302) · 31e3ae89
    fzyzcjy authored
    Close https://github.com/flutter/flutter/issues/126303
    
    When I encounter bugs in production environment saying null pointer error on `return _size!`, I wish I could know more information! However, currently the information is revealed by `assert(hasSize, 'RenderBox was not laid out: $this');`, thus *only* in debug mode can I know what is `this` (and/or more information that can be added), while in release mode I can only see a stack trace saying it is `RenderBox.size` that throws - nothing more :/
    
    Therefore, it is intuitive to add this extra information in release mode. However, will it affect performance? We all know this is in critical path and should be quite careful. Thus I did some experiments: https://godbolt.org/z/zPPPf5969 From my naive understanding of assembly, the two versions of code (`size!` vs `size ?? throw`) has the same assembly, except that they throw different types of errors. In other words, when there is no error, both code should be equivalent; when there is an error, surely the new code will be slower since it calls `this.toString()`, but the error handling process is rare and already heavy, so this is not a problem.
    
    ![image](https://user-images.githubusercontent.com/5236035/236962182-b9450d59-a2ac-426f-8300-3c7edcadf35e.png)
    31e3ae89
Name
Last commit
Last update
..
animated_size.dart Loading commit data...
binding.dart Loading commit data...
box.dart Loading commit data...
custom_layout.dart Loading commit data...
custom_paint.dart Loading commit data...
debug.dart Loading commit data...
debug_overflow_indicator.dart Loading commit data...
editable.dart Loading commit data...
error.dart Loading commit data...
flex.dart Loading commit data...
flow.dart Loading commit data...
image.dart Loading commit data...
layer.dart Loading commit data...
layout_helper.dart Loading commit data...
list_body.dart Loading commit data...
list_wheel_viewport.dart Loading commit data...
mouse_tracker.dart Loading commit data...
object.dart Loading commit data...
paragraph.dart Loading commit data...
performance_overlay.dart Loading commit data...
platform_view.dart Loading commit data...
proxy_box.dart Loading commit data...
proxy_sliver.dart Loading commit data...
rotated_box.dart Loading commit data...
selection.dart Loading commit data...
service_extensions.dart Loading commit data...
shifted_box.dart Loading commit data...
sliver.dart Loading commit data...
sliver_fill.dart Loading commit data...
sliver_fixed_extent_list.dart Loading commit data...
sliver_grid.dart Loading commit data...
sliver_group.dart Loading commit data...
sliver_list.dart Loading commit data...
sliver_multi_box_adaptor.dart Loading commit data...
sliver_padding.dart Loading commit data...
sliver_persistent_header.dart Loading commit data...
stack.dart Loading commit data...
table.dart Loading commit data...
table_border.dart Loading commit data...
texture.dart Loading commit data...
tweens.dart Loading commit data...
view.dart Loading commit data...
viewport.dart Loading commit data...
viewport_offset.dart Loading commit data...
wrap.dart Loading commit data...