[R-SIG-Mac] Dashed line not evenly separated

Simon Urbanek @|mon@urb@nek @end|ng |rom R-project@org
Fri Feb 25 22:31:43 CET 2022


John,

thanks for the timings. Actually, if you look closely, it's the other way around - R-devel is much faster - the median is about 1ms - while R 4.1.2 it is 25ms (that's why it's a really good idea to fix the units when using microbenchmarks).

But your timings gave me the idea to test different path lengths. On my old Intel machine with Catalina I actually don't see any timing difference between the two R versions, so it appears that modern macOS versions are much better at drawing long paths so I'm happy with the change. Also even on my old machine it is linear in the length of the path, so that's all good, multiple subpaths are apparently no longer necessary.

JZ,

the R-devel solution is best we can do - we are instructing the system to draw one path with the defined dashing. We have no control over how Apple implements that - the behavior at small sizes is really an Apple bug that we can't do anything about - you could file a Radar issue with Apple.

Cheers,
Simon



> On Feb 26, 2022, at 6:11 AM, John Fox <jfox using mcmaster.ca> wrote:
> 
> Dear JL and Simon,
> 
> I too tried the quartz graphics device in version r81808 of R-devel, and though it's a clear improvement, as JL mentioned, the dashed lines that it creates aren't evenly spaced.
> 
> I've attached a PDF created by saving the graph for my example from the quartz graphics device. Compare this to a PDF created by the pdf graphics device -- using a PDF viewer like Acrobat that renders the plot accurately. (I'm not sure whether PDF attachments are allowed on the list, but if not, it wouldn't be hard to recreate the graph.)
> 
> I also tried timing the computation in both R 4.1.2 and R-devel, with the following results:
> 
>  R 4.1.2
> 
> > microbenchmark(
>  +   plot(log10(1:1e4), lty = 2, type="l")
>  + )
> Unit: milliseconds
> expr      min       lq     mean   median
> plot(log10(1:10000), lty = 2, type = "l") 24.13186 25.89029 36.99181 26.05741
> uq      max neval
> 26.45445 1072.527   100
> 
>  R-devel:
> 
> > library("microbenchmark")
> > microbenchmark(
>  +   plot(log10(1:1e4), lty = 2, type="l")
>  + )
> Unit: microseconds
> expr     min      lq     mean   median
> plot(log10(1:10000), lty = 2, type = "l") 754.687 859.073 6372.026 944.4145
> uq      max neval
> 14259.37 38235.57   100
> 
> 
> So, as expected, the quartz device in R-devel is substantially slower.
> 
> Best,
> John
> 
> 
> On 2022-02-25 10:20 a.m., Zhang, Jialin wrote:
>> Hi Simon,
>> Thanks. I have tried the R-devel r81808 x86_64 and the plot has been improved significantly. The dashed lines are evenly separated as long as the window is reasonably large.
>> When the window is small, it still shows the same issue. The current one in r81808 is already good enough for me, I was wondering if it could be something like a well separated dashed line no matter the size of window.
>> Thanks again to others who confirmed and explored into this issue!
>> Best,
>> JZ
>>>> Jialin Zhang (JZ), Assistant Professor of Statistics
>> Department of Mathematics and Statistics
>> Mississippi State University
>> tel: (662) 325-7137; email: jzhang using math.msstate.edu <mailto:jzhang using math.msstate.edu>
>> *From: *Simon Urbanek <simon.urbanek using R-project.org>
>> *Date: *Thursday, February 24, 2022 at 7:57 PM
>> *To: *John Fox <jfox using mcmaster.ca>, Zhang, Jialin <jzhang using math.msstate.edu>
>> *Cc: *r-sig-mac using r-project.org <r-sig-mac using r-project.org>
>> *Subject: *Re: [R-SIG-Mac] Dashed line not evenly separated
>> FWIW I have checked the PDF, and it defines just one long path, so the rendering in Preview on macOS 11+ is simply wrong. It is rather curious that it is wrong in a way that is consistent with artificially breaking a path into subpaths internally - as if Apple was trying to do the same optimization that we did before and we do now know that it backfires ...
>> Cheers,
>> Simon
>> > On 25/02/2022, at 1:42 PM, Simon Urbanek <simon.urbanek using r-project.org> wrote:
>> >
>> > John,
>> >
>> > thanks, yes, interesting, the exact same PDF file looks just fine in macOS 10.15, but turns into solid line in macOS 11, so the problem has been introduced in PDF rendering between those macOS versions. I did not check the file so don't know whose rendering is correct.
>> >
>> > As for the Quartz device (Jialin's original question), we are splitting lines with many points into subpaths which means the dashing gets re-started at the beginning of each subpath. The current threshold is 100:
>> > https://secure-web.cisco.com/1griolpNGDcLmv9RxvpJYzPuEy3qfl7m0IWA8Sx0ZyyOFBIBFS3jTuktbKaa6o143gQ4x3aWKx-AX2mlMXqj2C7bNaza7OGymvG-gaM-HNDgNqe7zT0t06ylfTtIsEI474XvyKhOrOhGpFsO4vjTDwu45eI26oKaBN0i8S19S4JSrr4gV4F5nwNtYm2P9bYNTOn-T9RMiO5rqcXXIUJzE_Vy4UPko0sOJTv2JvrRTJtQoSjNETfUwv6gKtSqS9TodQdnPjSaSnNXtelyM-2fzKdBTUMtyYebM-CGvqHrhHuF9InS8Pvt7EWqJ-BrDlPW4/https%3A%2F%2Fgithub.com%2Fwch%2Fr-source%2Fblob%2Fe38463ce746882af90a4a5dc7e6c588d61669585%2Fsrc%2Flibrary%2FgrDevices%2Fsrc%2FdevQuartz.c%23L1146 <https://secure-web.cisco.com/1griolpNGDcLmv9RxvpJYzPuEy3qfl7m0IWA8Sx0ZyyOFBIBFS3jTuktbKaa6o143gQ4x3aWKx-AX2mlMXqj2C7bNaza7OGymvG-gaM-HNDgNqe7zT0t06ylfTtIsEI474XvyKhOrOhGpFsO4vjTDwu45eI26oKaBN0i8S19S4JSrr4gV4F5nwNtYm2P9bYNTOn-T9RMiO5rqcXXIUJzE_Vy4UPko0sOJTv2JvrRTJtQoSjNETfUwv6gKtSqS9TodQdnPjSaSnNXtelyM-2fzKdBTUMtyYebM-CGvqHrhHuF9InS8Pvt7EWqJ-BrDlPW4/https%3A%2F%2Fgithub.com%2Fwch%2Fr-source%2Fblob%2Fe38463ce746882af90a4a5dc7e6c588d61669585%2Fsrc%2Flibrary%2FgrDevices%2Fsrc%2FdevQuartz.c%23L1146>
>> >
>> > The theory was that no one in their right mind would create a line that has 100 points so close to each other that they wouldn't even span a dash. I guess that assumption was wrong ;). If I recall paths with too many points caused a problem long time ago, but it may no longer be the case so removing the threshold altogether is another option. I have done that in r81808 so you can try tonight's R-devel which should no longer exhibit that behavior, but see if that causes any performance issues.
>> >
>> > Cheers,
>> > Simon
>> >
>> >
>> >
>> >> On 25/02/2022, at 4:40 AM, John Fox <jfox using mcmaster.ca> wrote:
>> >>
>> >> Hi Duncan,
>> >>
>> >> Your message prompted me to investigate a bit further, and I discovered that the pdf looks right when I open it in Adobe Reader or Google Chrome but not in the (default) macOS Preview or Safari. That suggests to me that the problem may be in macOS.
>> >>
>> >> Just in case it's relevant, my session info:
>> >>
>> >>> sessionInfo()
>> >> R version 4.1.2 (2021-11-01)
>> >> Platform: aarch64-apple-darwin20 (64-bit)
>> >> Running under: macOS Monterey 12.1
>> >>
>> >> Matrix products: default
>> >> BLAS: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libRblas.0.dylib
>> >> LAPACK: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libRlapack.dylib
>> >>
>> >> locale:
>> >> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>> >>
>> >> attached base packages:
>> >> [1] stats     graphics  grDevices utils     datasets  methods   base
>> >>
>> >> loaded via a namespace (and not attached):
>> >> [1] compiler_4.1.2
>> >>
>> >>
>> >> Best,
>> >> John
>> >>
>> >>
>> >> On 2022-02-24 6:10 a.m., Duncan Murdoch wrote:
>> >>> On 23/02/2022 8:30 p.m., John Fox wrote:
>> >>>> Dear Ken,
>> >>>>
>> >>>> Yes, but I believe that it *should* work even in a small window. For
>> >>>> example, the following produces a proper broken line on Windows but not
>> >>>> on macOS:
>> >>>>
>> >>>>    pdf(width=3, height=3)
>> >>>>    plot(log10(1:1e4), lty = 2, type="l")
>> >>>>    dev.off()
>> >>>>
>> >>> That one looks fine on my Mac in the PDF output, but not on screen using the default quartz() device.
>> >>> R version 4.1.0 Patched (2021-07-09 r80614)
>> >>> Platform: x86_64-apple-darwin17.0 (64-bit)
>> >>> Running under: macOS Catalina 10.15.7
>> >>> Duncan Murdoch
>> >> --
>> >> John Fox, Professor Emeritus
>> >> McMaster University
>> >> Hamilton, Ontario, Canada
>> >> web: https://secure-web.cisco.com/1ObjcIb3ZLRhGIdX1wQLJ_j0S1fGyZRimQTtMh_xiIUe13dTZayGXqBWe8LFrIEPvB-T_sZEPsk_FBkg4kaQE7uNLJykoRbr_-CRwMOI-llJmWRAwSzLBkUZHvAuphCJ0plh9iqmpT_FxSB8s2HlXzzynAe2a6Cl1PhEXorKeoIN3nVV35C2vpaC0j-FcIQQ4Mq0Tp0Ypqx-MnAzFgHNlZQlNRbXKHdgQZHwpmAWwjeT3GxSNl9Zg9_31egYHp2ikIFgINFS_q2atSugvI8pgtlndaNyJzbVIRg5TzGFmdQwBWjx3gw8JfLkQARVNoeT9/https%3A%2F%2Fsocialsciences.mcmaster.ca%2Fjfox%2F <https://secure-web.cisco.com/1ObjcIb3ZLRhGIdX1wQLJ_j0S1fGyZRimQTtMh_xiIUe13dTZayGXqBWe8LFrIEPvB-T_sZEPsk_FBkg4kaQE7uNLJykoRbr_-CRwMOI-llJmWRAwSzLBkUZHvAuphCJ0plh9iqmpT_FxSB8s2HlXzzynAe2a6Cl1PhEXorKeoIN3nVV35C2vpaC0j-FcIQQ4Mq0Tp0Ypqx-MnAzFgHNlZQlNRbXKHdgQZHwpmAWwjeT3GxSNl9Zg9_31egYHp2ikIFgINFS_q2atSugvI8pgtlndaNyJzbVIRg5TzGFmdQwBWjx3gw8JfLkQARVNoeT9/https%3A%2F%2Fsocialsciences.mcmaster.ca%2Fjfox%2F>
>> >>
>> >> _______________________________________________
>> >> R-SIG-Mac mailing list
>> >> R-SIG-Mac using r-project.org
>> >> https://secure-web.cisco.com/12oatsNqPgE44sKbBvvEQlvqKgLckeuU3HfZ7Nyzgy03EnQsNa4dBGxTs9fmeLRfy8ANZrw64J0zvN7ExDQ1CwKR7IR2UtNmajNT0bqXJvmsgya-ZACfaY1oIIDx0f1fzyjJYaw7W7pRaAuIpEv2ScI-jM7djCu-D_uplmWKibD-3fhJr1AyWz1UOVawRCYujhuOl8G7Q8Z9l1H5yNRVYCECEG7U90UNuvAya60DI8YYuxF_xupE_lX76D2tKG2FuIEFXLFzlmylxkLRZpu4dhAyHOedzIu-M5bX0Bto2kcPEWzSJ7mqXox1HRzfst8My/https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-mac <https://secure-web.cisco.com/12oatsNqPgE44sKbBvvEQlvqKgLckeuU3HfZ7Nyzgy03EnQsNa4dBGxTs9fmeLRfy8ANZrw64J0zvN7ExDQ1CwKR7IR2UtNmajNT0bqXJvmsgya-ZACfaY1oIIDx0f1fzyjJYaw7W7pRaAuIpEv2ScI-jM7djCu-D_uplmWKibD-3fhJr1AyWz1UOVawRCYujhuOl8G7Q8Z9l1H5yNRVYCECEG7U90UNuvAya60DI8YYuxF_xupE_lX76D2tKG2FuIEFXLFzlmylxkLRZpu4dhAyHOedzIu-M5bX0Bto2kcPEWzSJ7mqXox1HRzfst8My/https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-mac>
>> >>
>> >
>> > _______________________________________________
>> > R-SIG-Mac mailing list
>> > R-SIG-Mac using r-project.org
>> > https://secure-web.cisco.com/12oatsNqPgE44sKbBvvEQlvqKgLckeuU3HfZ7Nyzgy03EnQsNa4dBGxTs9fmeLRfy8ANZrw64J0zvN7ExDQ1CwKR7IR2UtNmajNT0bqXJvmsgya-ZACfaY1oIIDx0f1fzyjJYaw7W7pRaAuIpEv2ScI-jM7djCu-D_uplmWKibD-3fhJr1AyWz1UOVawRCYujhuOl8G7Q8Z9l1H5yNRVYCECEG7U90UNuvAya60DI8YYuxF_xupE_lX76D2tKG2FuIEFXLFzlmylxkLRZpu4dhAyHOedzIu-M5bX0Bto2kcPEWzSJ7mqXox1HRzfst8My/https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-mac <https://secure-web.cisco.com/12oatsNqPgE44sKbBvvEQlvqKgLckeuU3HfZ7Nyzgy03EnQsNa4dBGxTs9fmeLRfy8ANZrw64J0zvN7ExDQ1CwKR7IR2UtNmajNT0bqXJvmsgya-ZACfaY1oIIDx0f1fzyjJYaw7W7pRaAuIpEv2ScI-jM7djCu-D_uplmWKibD-3fhJr1AyWz1UOVawRCYujhuOl8G7Q8Z9l1H5yNRVYCECEG7U90UNuvAya60DI8YYuxF_xupE_lX76D2tKG2FuIEFXLFzlmylxkLRZpu4dhAyHOedzIu-M5bX0Bto2kcPEWzSJ7mqXox1HRzfst8My/https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-mac>
>> >
> -- 
> John Fox, Professor Emeritus
> McMaster University
> Hamilton, Ontario, Canada
> web: https://socialsciences.mcmaster.ca/jfox/
> <R-devel.pdf>



More information about the R-SIG-Mac mailing list